Exception Handling

Category: Entertainment

Presentation Description

It includes a brief description on Exception handling


Presentation Transcript

slide 1:

w w w . j a v a 2 b l o g . c o m EXCEPTION HANDLING

slide 2:

CONTENT Introduction Types of Exception Handling try block catch block finally block throw vs throws

slide 3:

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.

slide 4:

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:

slide 5:

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:

slide 6:

TYPES OF EXCEPTION Errors are irrecoverable. Exa- VirtualMachineError StackOverFlowError OutOfMemoryError. Error:

slide 7:

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.

slide 8:

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.

slide 9:

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.

slide 10:

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.

slide 11:

w w w . j a v a 2 b l o g . c o m THANK YOU