Monday, 25 March 2013

How Exception Handling works?

At low level an exception is a java object with attributes and methods. When a problem occurs, an exception object is created, thrown and then handled.
exceptionFlow
As shown in above figure, exception handling can be grouped into these four phases. When a problem occurs it is the start of exception handling flow. A problem can be broadly classified into two. First one is, it can be handled and execution can continue, the second one is an unrecoverable serious situation which cannot be handled. An example for recoverable problem is, code block is expecting a value in a variable and it is not present. This can be handled by substituting a default value and the execution can continue. An easy example for unrecoverable condition is a hardware failure.
Java’s exception handling mechanism is object oriented. We have Throwable as the base class and all exceptions are sub classes of Throwable. We have Error and Exception as two immediate sub classes of Throwable.

No comments:

Post a Comment