Exception Handling:Basics
Exception Handling:-
Basic Definition:-
The term exception denotes an exceptional event that occured during program execution and
which alters normal flow of instructions.Exception handling goes handy in situations where
there is a possibility of unexpected or exceptional event.
Some unexpected situations are:-
1.Problem with network connectivity
2.arrays out of bounds
3.mathematical exceptions
4.Problem in I/O
Need for exception Handling:-
You cannot afford to have an application that stop working if requested file is missing.
To handle situations like above to avoid a crash exception handling is done.
Exception handling allows developers and programmers to detect errors easily without writing
special code. Even better, it lets us keep exception-handling code
cleanly separated from the exception-generating code. It also lets us use the same
exception-handling code to deal with a range of possible exceptions.
The Exception class:-
The class which is on top of hierarchy is called Throwable.Two classes are derived from it.
Error and Exception.
The Exception class is used for Exceptional conditions that have to be trapped in a program.
The Error class defines the conditions that usually do not occur in normal situations.
That is Error class is mainly used for catastophic failures such as VirtualMachineError etc.
Mechanism:-
Whenever an exception is raised,The Java Runtime System searches for an exception handler
in current method.If it does not found there then searches in calling method.
If handler is present nowhere it takes system default action as printing stack trace.


















0 comments:
Post a Comment
Post a Comment