Exceptions can occur at compile time and run time. c++ provides exception handling for run time errors. the keywords try, catch, throw are used to handle exceptions in c++.
Try:-
inorder to handle exception of a particular statements then the statements should be written in try block.
syntax:
try{list of statements;}
Throw:-
keyword throw is used to throw an exception occured at run time. this keyword throws an exception if it occurs. it throws the exception to the catch block.keyword throw throw's a value.
syntax:-
throw(variable);
catch:-
keyword catch is used to catch the exception throwed by throw statement. it catches the exception and executes the statements inside the catch block.
syntax:-
catch(list of variables){statements;}
important note:-
when an exception occurs, The exception is throwed to catch block and the statements inside the catch block is executed and the execution of the program end's there itself. It wont resume the execution after throwing an exception. so if you want to continue the execution after throwing the exception do not use exception handling technique. use conditional statement like if else.