EXCEPTIONS
Exception is an occurrence that alters
the normal program flow.
Program terminates when an exception
is throw...
Normal format of exception
handling
try{
risky code
}catch (Name of Exception){
What to do if an exception is
thrown
}
Finally Block
Definitely Executes
Try must be followed by,
1. a catch clause
2. many catch clauses
3. a finally block
4....
Exception Class
Java.lang.Exception
All Exceptions are sub classes of
the class Exception
Creating our own Exception by...
Exception Hierarchy
Throwable
Exceptions

Runtime
Exception

Interrupted
Exception

Arithmetic
Exception

Errors
Stackover...
Errors
Errors represent unusual
situations that have not caused by
the program.
Normally we cannot recover from
them.
S...
Using multiple catches &Trys
Catches must be in the same order as
exception hierarchy (sub class to super
class)
Largest...
Checked & Unchecked
Exceptions
Some Exceptions are checked in compile
time.
RuntimeExceptions and it’s subclasses
are un...
Re throwing Exceptions
We can re throw exceptions from the
catch clause.
Can give a try-catch from within a catch
clause...
JVM & Programmatically thrown
Exceptions
JVM exceptions – either exclusively or
most logically thrown by JVM.
Eg:- nullp...
Upcoming SlideShare
Loading in …5
×

Exceptions in Java

371
-1

Published on

This presentation provide a detailed introduction about Exceptions and Exception Handling in Java.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
371
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Exceptions in Java

  1. 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. 2. Normal format of exception handling try{ risky code }catch (Name of Exception){ What to do if an exception is thrown }
  3. 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
  4. 4. Exception Class Java.lang.Exception All Exceptions are sub classes of the class Exception Creating our own Exception by extending the class Exception The Keyword throw
  5. 5. Exception Hierarchy Throwable Exceptions Runtime Exception Interrupted Exception Arithmetic Exception Errors Stackoverflaw Error Assertion Error
  6. 6. Errors Errors represent unusual situations that have not caused by the program. Normally we cannot recover from them. So we don’t handle errors.
  7. 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. 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. 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. 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

×