Exception
Handling:
An
exception/error is an abnormal condition that breaks/disrupts the normal
program flow. The abnormal condition occurs at run-time i.e. during code
execution.
For
example, a C program gets terminated when division by zero is encountered at
the run-time as this is not a defined operation and result in run-time error.
The other familiar example in case of C-language is that of null pointer
exception, which occurs when we try to access a memory location through an
un-initialized pointer. The program gets terminated in this case also.
Java
has a separate construct for exception/error handling like C++. It is possible
to recover from an exception/error at run-time and continue the program
exception using the exception-handling construct.
A
java exception/error is an object of class Exception/Error or one of its
sub-class. JVM creates an object of class Exception/Error or one o f their sub-class whenever
exception/error occurs at the run –time. The exception/error object contains
details about the exception/error, which can be accessed using the public
methods provided for this purpose.
The are two immediate sub classes of class
Throwable:
1. Error
2. Exception
Exception is the runtime error. If we
have not specified a semi-colon, not declared a variables etc.. Then these all
errors at being notified the complier, so these are known as the compile time error
But, if we divide a number by zero, if
we access an element in an array outside its bound then an exception is
occurred, and this all will occur at the run-time
Comments
Post a Comment