Exception Handling
Exception Handling
This process involves separate error handling code that performs the
following tasks
Identify the problem (Hit the exception)
Report that an error has occurred (Throw the exception)
Receive the error information (Catch the exception)
Take corrective actions (Handles the exception)
Exception Handling Model
try block
Exception object
catch block
2
The keyword try is used to preface a block of statements
surrounded by braces which may be generating
exceptions; this block of statements is known as try
block
catch block
5
Most often, exceptions are thrown by functions that are invoked
from within the try block
The point at which the throw block is executed is called the throw
point
void Xhandler(int
test) { void main() {
try{ cout << "Start\n";
if(test) throw test;Xhandler(1);
Xhandler(2);
else throw "Value
is zero"; Xhandler(0);
Xhandler(3);
}
cout << “End"; }
catch(int i) {
cout << "Caught
Exception #: " << i; Start