Search This Blog

27 June, 2011

Exception handling: Java specific part-1


Part - 1
In Java exception handling is done through 5 keywords.


– throw
– try
– catch
– throws
– finally


• When an exception is thrown,


– not only is the stack unwound to a
previously saved state, but
– automatic objects are marked for
finalization (destructors are exeecuted in
C++)
– if the exception is thrown from within a
constructor, the finalizer of that object is
not executed.
– key resources may be manually freed
through the use of a finally block which is
guaranteed to execute, whether or not an
exception is thrown.


• The code to be monitored is put into a a try block.


• The action to be taken, when an exception is
thrown is put into various catch blocks.



• Each catch block decides what action is to be
taken when a particular exception is thrown. try{//try block
}
catch (Exception_type1 arg)
{ //catch block
}
catch (Exceptiontype2 arg)
{ //catch block 2
}
.............................................      Part - 2   .....................................

No comments:

Post a Comment

Meetme@