Error or Exception handling in C++: try, catch and throw keywords

Exception handling is used to manage and automate run time errors. For handling exceptions C++ uses three keywords try, catch and throw. A try region of code is used to monitor the errors or exceptions in a program. catch keyword is used to catch an error and throw is used to throw the error in the program.

Syntax of try , catch:

try {


catch (type1 arguments) {


catch (type2 arguments) {


catch (typeN arguments) {


Syntax of throw:

throw exception;

Within a try region there can be any number of catch statements. When an exception is thrown by throw, it is caught by catch and then it is processed in an orderly fashion.

Leave a Reply