In
general, exceptions are run-time errors caused due to logical mistakes occurred
during program execution because of its wrong input. For example – Creating an
array with negative number as size. Here, size of the array can’t be negative.
Hence, the exception “java.lang.NegativeArraySizeException”
is thrown representing the logical mistake in giving the size of array.
An
exception is an event, which occurs during the execution of a program that
disrupts the normal execution flow of the program instructions. It is a signal
that indicates some sort of abnormal condition (such as an error) that has
occurred in a code sequence at run time. In java exception is an object that is
an instance of some subclass of java.lang.Throwable, so to catch that exception
we must define a catch block with that exception class name.
Throwable class – It is
the super class of all exceptions in java. Only objects those are instances of
this class (or one of its subclass) are thrown by JVM or can be thrown by the
java developer using throw statement. Similarly, only this class or one of its
subclass can be the argument type in the catch clause.
Throwable class Hierarchy -
No comments:
Post a Comment