Professional Documents
Culture Documents
Exception Handling
Exception Handling
Exception Handling
EXCEPTIONS CAN`T BE
ELIMINATED COMPLETELY. THEY ARE BOUND TO OCCUR IN
JAVA PROGRAM.
YOU BETTER KNOW HOW TO DEAL WITH THEM IN AN
OBJECT-ORIENTED MANNER….
REPRESENTED BY
PAYAL MOURYA
WHAT IS EXCEPTION IN JAVA ?
• The errors that occur at runtime. i.e. during execution of the program are called
exceptions.
• An exception is unexcepted / unwanted /abnormal situation that occurred.
• The reason why exception occur are numerous..
• ClassNotFoundException
• Falling short of memory
• Division by Zero
• Stack overflow
JAVA EXCEPTION USES FIVE KEYWORDS
throws
catch try
throw
finally
KEYWORDS DISCRIPTION
• The “try” keyword is used to specify
TRY a block where we should place an
exception code. It means we can’t
use try block alone. The try block
must be followed by either catch or
finally.
Throws
FINALLY:
• JAVA supports another statement known as finally statement that can be used to handle an
exception that is not caught by any of the previous catch statements.
• We can put finally block after the try block or after the last catch block.
• The finally block is executed in all circumstances. Even if a try block completes without
problems, the finally block executes.
EXCEPTION HIERARCHY
Throwable
Error Exception
IOException RunTimeException
THE EXCEPTION CLASS HAS TWO MAIN SUBCLASSES:
• Exceptions that must be included in a method’s throws list if that method can generate one of
these exceptions and does not handle it itself. These are called CHECKED EXCEPTIONS.
• For example , if a file is to be opened, but the file cannot be found, an exception occurs.
Exceptions need not be included in any method’s throws list. These are called
UNCHECKED EXCEPTIONS because the complier does not check to see if a method
handles or throws these exceptions.