1. EXCEPTIONS
Exception is an occurrence that alters
the normal program flow.
Program terminates when an exception
is thrown.
To avoid from this, we must handle the
exceptions.
Try block & Catch clause.
2. Normal format of exception
handling
try{
risky code
}catch (Name of Exception){
What to do if an exception is
thrown
}
3. Finally Block
Definitely Executes
Try must be followed by,
1. a catch clause
2. many catch clauses
3. a finally block
4. catch clauses and a finally block
No code between try and catch
7. Using multiple catches &Trys
Catches must be in the same order as
exception hierarchy (sub class to super
class)
Largest catch must be the last.
Some exceptions cannot use without a
risk. eg:-IOException,InterruptedException
Multiple trys & trys inside try is possible.
8. Checked & Unchecked
Exceptions
Some Exceptions are checked in compile
time.
RuntimeExceptions and it’s subclasses
are unchecked.
Others are checked in compile time.
The keyword throws is used to guard
risky methods. It’s not handling &just
passing the bulk.
9. Re throwing Exceptions
We can re throw exceptions from the
catch clause.
Can give a try-catch from within a catch
clause.
Cannot use the same Exception name in
re throwing.
10. JVM & Programmatically thrown
Exceptions
JVM exceptions – either exclusively or
most logically thrown by JVM.
Eg:- nullpointer exception
Programmatic – thrown by application
and/or programmer.
Eg:- NumberformatException,
IllegalArgumentException