WELCOME TO PRESENTATION
Exception Handling
Exception Handling…
• What is Exception?
“ An Exception is an unwanted /unexpected/abnormal Situation
which occurs during the execution of program i.e. at run time, that
disrupts the normal flow of the program’s instruction”.
Exception Handling…
“ Exception Handling is a mechanism to handle Run Time Errors”.
or
“The Exception Handling in Java is one of the powerful mechanism to
handle the runtime errors so that normal flow of the application can be
maintained”.
Advantage:
• Maintain the normal flow of the program
Exception Handling…
5Keywords Used for Exception Handling
• Try
• Catch
• Finally
• throw
• throws
Exception Handling…
try block
• What is try block?
“ whenever we write a statement and if that statement is error
suspecting or code is risky then we put that code/statement inside the
try block”.
“ try is a block that contains only risky code”.
Exception Handling…
Catch :
• What is catch block?
“ The main purpose of the catch is to handle the exception which are
throws by try block”.
“It is used to handle the exception”.
Note:
catch block will not be executed if there is no exception inside
the block.
8
Exception Handling…
• Java Exception Keywords
Exception Handling…
Finally:
• What is finally block?
“ finally block is a Realtime block and the main purpose of this
finally block is to handle the resource”.
“ It is always executed whether exception is caused or not”.
Flow chat for Finally
Start
Excep
tion
Ignore the rest code
of try block
Execute catch
block
END
Ignore catch block
Finally
yes
No
11
Exception Handling…
• Java Exception Keywords
Exception Handling…
throw
What is throw block?
“ throw keyword is used to throw the user defined or customized
exception object to the JVM explicitly”.
Exception Handling…
throws
• What is throws ?
“ throws keyword is used when we doesn’t want to handle the
exception and try to send the exception to the JVM.
14
Exception Handling…
• Java Exception Keywords
15
Exception Handling…
Types of Java Exceptions
There are mainly two types of exceptions: checked and unchecked. Here,
an error is considered as the unchecked exception. there are three types of
exceptions:
1. Checked Exception
2. Unchecked Exception
3. Error
Types of Exceptions:
checked Exceptions: Compile time exception
Unchecked Exceptions: Run Time Exceptions
Run Time Exceptions are:-
1. Arithmetic Exceptions
2. Number Format Exceptions
3. Array Index Out of Bounds Exception
4. Null Point Exceptions
17
Exception Handling…
• Java Exception Keywords
18
Exception Handling…
• Java Exception Keywords
Difference between Exception & Error
Exception Error
Exception is caused by our program
Exceptions are recoverable
Exceptions are classified as checked and
unchecked type
Exceptions are not caused by our
program
Errors are not recoverable
Errors are only unchecked type in java
Thank you

Exception Handling computer science concept java

  • 1.
  • 2.
  • 3.
    Exception Handling… • Whatis Exception? “ An Exception is an unwanted /unexpected/abnormal Situation which occurs during the execution of program i.e. at run time, that disrupts the normal flow of the program’s instruction”.
  • 4.
    Exception Handling… “ ExceptionHandling is a mechanism to handle Run Time Errors”. or “The Exception Handling in Java is one of the powerful mechanism to handle the runtime errors so that normal flow of the application can be maintained”. Advantage: • Maintain the normal flow of the program
  • 5.
    Exception Handling… 5Keywords Usedfor Exception Handling • Try • Catch • Finally • throw • throws
  • 6.
    Exception Handling… try block •What is try block? “ whenever we write a statement and if that statement is error suspecting or code is risky then we put that code/statement inside the try block”. “ try is a block that contains only risky code”.
  • 7.
    Exception Handling… Catch : •What is catch block? “ The main purpose of the catch is to handle the exception which are throws by try block”. “It is used to handle the exception”. Note: catch block will not be executed if there is no exception inside the block.
  • 8.
  • 9.
    Exception Handling… Finally: • Whatis finally block? “ finally block is a Realtime block and the main purpose of this finally block is to handle the resource”. “ It is always executed whether exception is caused or not”.
  • 10.
    Flow chat forFinally Start Excep tion Ignore the rest code of try block Execute catch block END Ignore catch block Finally yes No
  • 11.
  • 12.
    Exception Handling… throw What isthrow block? “ throw keyword is used to throw the user defined or customized exception object to the JVM explicitly”.
  • 13.
    Exception Handling… throws • Whatis throws ? “ throws keyword is used when we doesn’t want to handle the exception and try to send the exception to the JVM.
  • 14.
  • 15.
    15 Exception Handling… Types ofJava Exceptions There are mainly two types of exceptions: checked and unchecked. Here, an error is considered as the unchecked exception. there are three types of exceptions: 1. Checked Exception 2. Unchecked Exception 3. Error
  • 16.
    Types of Exceptions: checkedExceptions: Compile time exception Unchecked Exceptions: Run Time Exceptions Run Time Exceptions are:- 1. Arithmetic Exceptions 2. Number Format Exceptions 3. Array Index Out of Bounds Exception 4. Null Point Exceptions
  • 17.
  • 18.
  • 19.
    Difference between Exception& Error Exception Error Exception is caused by our program Exceptions are recoverable Exceptions are classified as checked and unchecked type Exceptions are not caused by our program Errors are not recoverable Errors are only unchecked type in java
  • 20.