Which block is used to handle an exception in C++?
Options
- A. try
- B. catch
- C. throw
- D. More than one of the above
- E. None of the above
Quiz Practice:
B. catch
Answer: (B) catch
The catch block is used to handle an exception thrown from a corresponding try block.
The general structure is:
try { /* risky code */ } catch(...) { /* handling code */ }
The try block identifies code that may generate an exception, while the catch block provides the code for handling that exception.