SlideShare a Scribd company logo
1 of 16
Download to read offline
Exception Handling
What is exception ?
● An exception is an event that occurs during the
execution of a program that disrupts the
normal flow of instructions.
● Anything that occurs in an unexpected way is
called as exception
Error
● These are not exceptions at all, but problems
that arise beyond the control of the user or the
programmer.
● Errors are typically ignored in your code
because you can rarely do anything about an
error.
Difference between Error and
Exception
● An Error "indicates serious problems that a
reasonable application should not try to catch.”
● An Exception "indicates conditions that a
reasonable application might want to catch."
Why exception occurs
An exception can occur for many different
reasons, including the following:
● A user has entered invalid data.
● A file that needs to be opened cannot be
found.
● A network connection has been lost in the
middle of communications or the JVM has run
out of memory.
●
Types of Exceptions
● Checked exceptions
● Runtime exceptions
Checked Exception
● A checked exception is an exception that is
typically a user error or a problem that cannot
be foreseen by the programmer.
● 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.
Runtime Exception
● A runtime exception is an exception that
occurs that probably could have been avoided
by the programmer.
● As opposed to checked exceptions, runtime
exceptions are ignored at the time of
compilation.
Categories of exception
●
In Java, it is possible to define two catergories of Exceptions and Errors.
● JVM Exceptions: - These are exceptions/errors that are exclusively or
logically thrown by the JVM.
●
Examples : NullPointerException, ArrayIndexOutOfBoundsException,
ClassCastException,
● Programmatic exceptions: - These exceptions are thrown explicitly by
the application or the API programmers
●
Examples: IllegalArgumentException, IllegalStateException.
Advantages of exception handling
● Separating Error-Handling Code from
"Regular" Code
● Grouping and Differentiating Error Types
Keywords to handle exceptions
Exception Handling contains 5 keywords
● 1. try
● 2. catch
● 3. finally
● 4. throws
● 5. throw
Syntax for Exception handling
try
{}
catch(Exception e){
}
Finally{
}
Purpose of try, catch and finally
● The try block identifies a block of code in which an
exception can occur.
● The catch block identifies a block of code, known as an
exception handler, that can handle a particular type of
exception.
● The finally block identifies a block of code that is
guaranteed to execute, and is the right place to close
files, recover resources, and otherwise clean up after the
code enclosed in the try block.
●
Exception Hierarchy
Example of Exception handling
Sample output

More Related Content

What's hot

7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handling
Deepak Sharma
 

What's hot (14)

Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handling
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Java exeptions
Java exeptionsJava exeptions
Java exeptions
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exception handling
Exception handlingException handling
Exception handling
 
exception handling
exception handlingexception handling
exception handling
 
Exception handling basic
Exception handling basicException handling basic
Exception handling basic
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 

Viewers also liked (10)

Citizenship badge s2 poverty
Citizenship badge s2 povertyCitizenship badge s2 poverty
Citizenship badge s2 poverty
 
PASOS PARA UTLIZAR PROJECT
PASOS PARA UTLIZAR PROJECTPASOS PARA UTLIZAR PROJECT
PASOS PARA UTLIZAR PROJECT
 
Ddmd
DdmdDdmd
Ddmd
 
Biology Groupwork Homework
Biology Groupwork HomeworkBiology Groupwork Homework
Biology Groupwork Homework
 
Bbc
BbcBbc
Bbc
 
chmsc lab. school science project
chmsc lab. school science projectchmsc lab. school science project
chmsc lab. school science project
 
13 INSPIRATIONAL QUOTES TO MOTIVATE YOU IN 2013
13 INSPIRATIONAL QUOTES TO MOTIVATE YOU IN 201313 INSPIRATIONAL QUOTES TO MOTIVATE YOU IN 2013
13 INSPIRATIONAL QUOTES TO MOTIVATE YOU IN 2013
 
Bivariate model group6
Bivariate model group6Bivariate model group6
Bivariate model group6
 
The human tongue
The human tongueThe human tongue
The human tongue
 
Power point kor
Power point korPower point kor
Power point kor
 

Similar to Exception handling

Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 
Design byexceptions
Design byexceptionsDesign byexceptions
Design byexceptions
Asif Tasleem
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
Vadym Lotar
 
Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertions
phanleson
 

Similar to Exception handling (20)

Exception handling
Exception handlingException handling
Exception handling
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
Exception handling
Exception handlingException handling
Exception handling
 
Design byexceptions
Design byexceptionsDesign byexceptions
Design byexceptions
 
UNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and MultithreadingUNIT-3.pptx Exception Handling and Multithreading
UNIT-3.pptx Exception Handling and Multithreading
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Excception handling
Excception handlingExcception handling
Excception handling
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.ppt
 
exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handling
 
Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertions
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1
 
EXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograamingEXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograaming
 
Types of Exceptionsfsfsfsdfsdfdsfsfsdfsd
Types of ExceptionsfsfsfsdfsdfdsfsfsdfsdTypes of Exceptionsfsfsfsdfsdfdsfsfsdfsd
Types of Exceptionsfsfsfsdfsdfdsfsfsdfsd
 
lecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).pptlecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
 

More from Muthukumaran Subramanian

More from Muthukumaran Subramanian (20)

Struts introduction
Struts introductionStruts introduction
Struts introduction
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
 
Overriding methods
Overriding methodsOverriding methods
Overriding methods
 
Oops (inheritance&interface)
Oops (inheritance&interface)Oops (inheritance&interface)
Oops (inheritance&interface)
 
Non access modifiers
Non access modifiersNon access modifiers
Non access modifiers
 
Jdbc connectivity in java
Jdbc connectivity in javaJdbc connectivity in java
Jdbc connectivity in java
 
Garbage collection in java
Garbage collection in javaGarbage collection in java
Garbage collection in java
 
Files in java
Files in javaFiles in java
Files in java
 
Date class
Date classDate class
Date class
 
Currency class
Currency classCurrency class
Currency class
 
Timer class in java
Timer class in javaTimer class in java
Timer class in java
 
Calendar class in java
Calendar class in javaCalendar class in java
Calendar class in java
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
intorduction to Arrays in java
intorduction to Arrays in javaintorduction to Arrays in java
intorduction to Arrays in java
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Abstract classes
Abstract classesAbstract classes
Abstract classes
 
Java introduction
Java introductionJava introduction
Java introduction
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Exception handling

  • 2. What is exception ? ● An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions. ● Anything that occurs in an unexpected way is called as exception
  • 3. Error ● These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. ● Errors are typically ignored in your code because you can rarely do anything about an error.
  • 4. Difference between Error and Exception ● An Error "indicates serious problems that a reasonable application should not try to catch.” ● An Exception "indicates conditions that a reasonable application might want to catch."
  • 5. Why exception occurs An exception can occur for many different reasons, including the following: ● A user has entered invalid data. ● A file that needs to be opened cannot be found. ● A network connection has been lost in the middle of communications or the JVM has run out of memory. ●
  • 6. Types of Exceptions ● Checked exceptions ● Runtime exceptions
  • 7. Checked Exception ● A checked exception is an exception that is typically a user error or a problem that cannot be foreseen by the programmer. ● 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.
  • 8. Runtime Exception ● A runtime exception is an exception that occurs that probably could have been avoided by the programmer. ● As opposed to checked exceptions, runtime exceptions are ignored at the time of compilation.
  • 9. Categories of exception ● In Java, it is possible to define two catergories of Exceptions and Errors. ● JVM Exceptions: - These are exceptions/errors that are exclusively or logically thrown by the JVM. ● Examples : NullPointerException, ArrayIndexOutOfBoundsException, ClassCastException, ● Programmatic exceptions: - These exceptions are thrown explicitly by the application or the API programmers ● Examples: IllegalArgumentException, IllegalStateException.
  • 10. Advantages of exception handling ● Separating Error-Handling Code from "Regular" Code ● Grouping and Differentiating Error Types
  • 11. Keywords to handle exceptions Exception Handling contains 5 keywords ● 1. try ● 2. catch ● 3. finally ● 4. throws ● 5. throw
  • 12. Syntax for Exception handling try {} catch(Exception e){ } Finally{ }
  • 13. Purpose of try, catch and finally ● The try block identifies a block of code in which an exception can occur. ● The catch block identifies a block of code, known as an exception handler, that can handle a particular type of exception. ● The finally block identifies a block of code that is guaranteed to execute, and is the right place to close files, recover resources, and otherwise clean up after the code enclosed in the try block. ●