SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Andere mochten auch

Citizenship badge s2 poverty
Citizenship badge s2 povertyCitizenship badge s2 poverty
Citizenship badge s2 povertyWinoal875
 
Biology Groupwork Homework
Biology Groupwork HomeworkBiology Groupwork Homework
Biology Groupwork HomeworkWarakWarakMethod
 
chmsc lab. school science project
chmsc lab. school science projectchmsc lab. school science project
chmsc lab. school science projectAira Mae Semillano
 
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 2013braveish
 
Bivariate model group6
Bivariate model group6Bivariate model group6
Bivariate model group6Sambit Mishra
 

Andere mochten auch (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
 

Ähnlich wie 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 allHayomeTakele
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
Design byexceptions
Design byexceptionsDesign byexceptions
Design byexceptionsAsif Tasleem
 
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 MultithreadingSakkaravarthiS1
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in JavaVadym Lotar
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Javaankitgarg_er
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.pptJAYESHRODGE
 
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 2thenmozhip8
 
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 handlingKuntal Bhowmick
 
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 & Assertionsphanleson
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1Shinu Suresh
 
EXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograamingEXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograamingMuskanNazeer
 
Types of Exceptionsfsfsfsdfsdfdsfsfsdfsd
Types of ExceptionsfsfsfsdfsdfdsfsfsdfsdTypes of Exceptionsfsfsfsdfsdfdsfsfsdfsd
Types of Exceptionsfsfsfsdfsdfdsfsfsdfsdssuserce9e9d
 
lecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).pptlecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).pptZeeshanAli593762
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in JavaJava2Blog
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handlingraksharao
 

Ähnlich wie 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
 

Mehr von 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
 

Kürzlich hochgeladen

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
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...pradhanghanshyam7136
 
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.pptxDr. Ravikiran H M Gowda
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
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 POSCeline George
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
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 17Celine George
 

Kürzlich hochgeladen (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
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...
 
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
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
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
 

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