www.java2blog.com
EXCEPTION HANDLING
CONTENT
Introduction
Types of Exception Handling
try block
catch block
finally block
throw vs throws
INTRODUCTION
An exception is an abnormal condition which occurs
during the execution of a program. To handle the
Exception we use exception handling mechanism.
Exception handling helps to maintain the normal flow
of execution of an application.
TYPES OF EXCEPTION
An exception that is checked at compile time is
known as checked Exceptions. Examples of
Checked Exception are IOException,
SQLException, ClassNotFoundException.
Checked Exception:
TYPES OF EXCEPTION
An exception that is not checked at compile time is
known as an unchecked exception. Examples of
Unchecked Exception are ArithmeticException,
NullPointerException, NumberFormatException.
Unchecked Exception:
TYPES OF EXCEPTION
Errors are irrecoverable.
Exa- VirtualMachineError,
StackOverFlowError,
OutOfMemoryError.
Error:
TRY BLOCK
It must be followed either by finally block or
Catch block.
It must be used within a method.
Try block is used to wrap the code that may throw
an exception.
CATCH BLOCK
A catch block can be used only after the try
block.
All the catch block must be ordered from subclass
exception to super class exception.
The catch block is used to handle the exception.
multiple catch block can be within a single try block.
FINALLY BLOCK
We put the cleanup code into the finally
block like closing a file.
A finally block will not execute only when If the
program terminates through System.exit() or If
causing a fatal error.
A finally block is executed always whether the
exception is handled or not.
THROW VS THROWS
throws keyword is used to declare an exception. It
provides information to the programmer that there may
occur an exception so It is programmer’s responsibility
to provide exception handler so that the normal flow of
application can be maintained
throw keyword is used to explicitly throw an exception.
It is generally used to throw a custom exception (User
defined exception). It is used within a method body.
www.java2blog.com
THANK YOU

Exception Handling in Java

  • 1.
  • 2.
    CONTENT Introduction Types of ExceptionHandling try block catch block finally block throw vs throws
  • 3.
    INTRODUCTION An exception isan abnormal condition which occurs during the execution of a program. To handle the Exception we use exception handling mechanism. Exception handling helps to maintain the normal flow of execution of an application.
  • 4.
    TYPES OF EXCEPTION Anexception that is checked at compile time is known as checked Exceptions. Examples of Checked Exception are IOException, SQLException, ClassNotFoundException. Checked Exception:
  • 5.
    TYPES OF EXCEPTION Anexception that is not checked at compile time is known as an unchecked exception. Examples of Unchecked Exception are ArithmeticException, NullPointerException, NumberFormatException. Unchecked Exception:
  • 6.
    TYPES OF EXCEPTION Errorsare irrecoverable. Exa- VirtualMachineError, StackOverFlowError, OutOfMemoryError. Error:
  • 7.
    TRY BLOCK It mustbe followed either by finally block or Catch block. It must be used within a method. Try block is used to wrap the code that may throw an exception.
  • 8.
    CATCH BLOCK A catchblock can be used only after the try block. All the catch block must be ordered from subclass exception to super class exception. The catch block is used to handle the exception. multiple catch block can be within a single try block.
  • 9.
    FINALLY BLOCK We putthe cleanup code into the finally block like closing a file. A finally block will not execute only when If the program terminates through System.exit() or If causing a fatal error. A finally block is executed always whether the exception is handled or not.
  • 10.
    THROW VS THROWS throwskeyword is used to declare an exception. It provides information to the programmer that there may occur an exception so It is programmer’s responsibility to provide exception handler so that the normal flow of application can be maintained throw keyword is used to explicitly throw an exception. It is generally used to throw a custom exception (User defined exception). It is used within a method body.
  • 11.