C++ | Exception Handling | Question 1
#include <iostream> using namespace std; int main() { int x = -1; try { cout << "Inside try \n"; if (x < 0) { throw x; cout << "After throw \n"; } } catch (int x ) { cout << "Exception Caught \n"; } cout << "After catch \n"; return 0; } |
chevron_right
filter_none
(A)
Inside try Exception Caught After throw After catch
(B)
Inside try Exception Caught After catch
(C)
Inside try Exception Caught
(D)
Inside try After throw After catch
Answer: (B)
Explanation: When an exception is thrown, lines of try block after the throw statement are not executed.
When exception is caught, the code after catch block is executed. Catch blocks are generally written at the end through.
Quiz of this Question
Recommended Posts:
- C++ | Exception Handling | Question 4
- C++ | Exception Handling | Question 6
- C++ | Exception Handling | Question 3
- C++ | Exception Handling | Question 2
- C++ | Exception Handling | Question 7
- C++ | Exception Handling | Question 8
- C++ | Exception Handling | Question 5
- C++ | Exception Handling | Question 11
- C++ | Exception Handling | Question 12
- C++ | Exception Handling | Question 10
- C++ | Exception Handling | Question 9
- Java | Exception Handling | Question 1
- Java | Exception Handling | Question 3
- Java | Exception Handling | Question 4
- Java | Exception Handling | Question 2


