Exception Handling

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

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.

 catch • The catch block is used handle the


exception. It must be preceded by try
block which means we can’t use catch
block alone. It can be followed by finally
block later.
KEYWORDS DESCRIPTION
 Finally
•The “finally” block is used to execute the necessary
code of the program. It is executed whether an
exception is handled or not.

•The “throw’ keyword is used to throw an exception.


 Throw
•The “ throws” keyword is used to declare
exceptions. It specifies that there may occur an
exception in the method. It doesn’t throw an
exception. It is always used with method signature .

 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:

• (1) IOException or Checked Exception class and

• (2) RuntimeException or Unchecked Exception class


1) IOEXCEPTION OR CHECKED EXCEPTION :

• 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.

• These exceptions cannot simply be ignored at the time of compilation.


2) RuntimeException or Unchecked Exception:

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.

As opposed to checked exceptions, runtime exceptions are ignored at the time of


compilation.
CONCLUSION :
• Exceptions are a powerful error handling mechanism.

• Exceptions in Java are built into the language.

• Exceptions can be handled by the programmer, or handled by the


Java environment.

• Exception handling can only hide the errors.

• It cannot correct the errors.


THANKYOU

You might also like