in C Plus Plus by

What is Exception Handling? Does C++ support Exception Handling?

▼ Show 1 Answer

0 votes

Yes C++ supports exception handling.

We cannot ensure that code will execute normally at all times. There can be certain situations that might force the code written by us to malfunction, even though it’s error-free. This malfunctioning of code is called Exception.

When an exception has occurred, the compiler has to throw it so that we know an exception has occurred. When an exception has been thrown, the compiler has to ensure that it is handled properly, so that the program flow continues or terminates properly. This is called the handling of an exception.

Thus in C++, we have three keywords i.e. try, throw and catch which are in exception handling.

The general syntax for exception block is:



 # Code that is potentially about to throw exception goes here


 throw exception;


 catch(exception type) {


 #code to handle exception goes here


As shown above, the code that might potentially malfunction is put under the try block. When code malfunctions, an exception is thrown. This exception is then caught under the catch block and is handled i.e. appropriate action is taken.

Learn More with Madanswer

Related questions

0 votes
asked Jun 15, 2020 in C Plus Plus by Robindeniel