SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
Exception Handling in Java
Prof. Neeraj Bhargava
Kapil Chauhan
Department of Computer Science
School of Engineering & Systems Sciences
MDS University, Ajmer
Exception Handling in Java
 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.
 An exception (or exceptional event) is a problem that
arises during the execution of a program.
What is Exception Handling
 Exception Handling is a mechanism to handle runtime
errors such as ClassNotFoundException, IOException,
SQLException, RemoteException, etc.
Types of Java Exceptions
 There are mainly two types of exceptions: checked and
unchecked. Here, an error is considered as the
unchecked exception.
 Checked Exception
 Unchecked Exception
Difference between Checked
and Unchecked Exceptions
 1) Checked Exception
 The classes which directly inherit Throwable class
except RuntimeException and Error are known as
checked exceptions e.g. IOException, SQLException
etc. Checked exceptions are checked at compile-time.
Cont..
 2) Unchecked Exception
 The classes which inherit RuntimeException are
known as unchecked exceptions e.g.
ArithmeticException, NullPointerException,
ArrayIndexOutOfBoundsException etc. Unchecked
exceptions are not checked at compile-time, but they
are checked at runtime.
Java Exception Keywords
 Try
 The "try" keyword is used to specify a block where we
should place exception code. The try block must be
followed by either catch or finally. It means, we can't
use try block alone.
 Catch
 The "catch" block is used to handle the exception. It
must be preceded by try block which means we can't
use catch block alone. It can be followed by finally
block later.
Cont..
 Finally
 The "finally" block is used to execute the important
code of the program. It is executed whether an
exception is handled or not.
 Throw
 The "throw" keyword is used to throw an exception.
Java Exception Handling Example
 public class JavaExceptionExample{
 public static void main(String args[]){
 try{
 //code that may raise exception
 int data=100/0;
 }catch(ArithmeticException e){System.out.println(e);}
 //rest code of the program
 System.out.println("rest of the code...");
 }
 }
Assignment
 Explain Exception handling in java with example.

More Related Content

PPTX
Exception handling in java
PPT
exception handling in java
PPTX
Java Exception Handling
ODP
Exception Handling In Java 15734
PPTX
Exception handling in java
PPTX
Exception handling in JAVA
PPT
Exception handling
PPTX
Exception handling in java
Exception handling in java
exception handling in java
Java Exception Handling
Exception Handling In Java 15734
Exception handling in java
Exception handling in JAVA
Exception handling
Exception handling in java

What's hot (20)

PPTX
Exception Handling in Java
PPTX
Exception handling in java
PPTX
Java exception handling
PDF
Exception handling basic
PPTX
Java Exception Handling and Applets
PPTX
Exceptional Handling in Java
ODP
Exception Handling In Java
PPTX
Exception handling in java
PPTX
Z blue exception
PPTX
Exceptions in java
PPT
exception handling
PDF
Exception Handling in Java
PPT
Types of exceptions
PPTX
Exception handling
PPT
Java exception
PPTX
Exception handling in Java
PPTX
Exceptionhandling
PPTX
Presentation on-exception-handling
PPT
Exception handling
Exception Handling in Java
Exception handling in java
Java exception handling
Exception handling basic
Java Exception Handling and Applets
Exceptional Handling in Java
Exception Handling In Java
Exception handling in java
Z blue exception
Exceptions in java
exception handling
Exception Handling in Java
Types of exceptions
Exception handling
Java exception
Exception handling in Java
Exceptionhandling
Presentation on-exception-handling
Exception handling
Ad

Similar to Exception handling in java (20)

DOCX
VTU MCA 2022 JAVA Exceeption Handling.docx
PPTX
using Java Exception Handling in Java.pptx
PPT
Java Exception Handling & IO-Unit-3 (1).ppt
PPTX
Exception handling in java
PPTX
Lec-01 Exception Handling in Java_javatpoint.pptx
PPTX
OBJECT ORIENTED PROGRAMMING_Unit3_NOTES first half.pptx
PPT
A36519192_21789_4_2018_Exception Handling.ppt
PPTX
L14 exception handling
PPTX
Exception handling in java.pptx
PPTX
Java chapter 6
PPT
Exception Handling in JAVA
PDF
Chapter 5 Exception Handling (1).pdf
PPTX
Java Exceptions and Exception Handling
PPTX
presentationon exception handling in java.pptx
PPTX
Exception Handling computer science concept java
PDF
Java_Exception-CheatSheet_Edureka.pdf
PPTX
EXCEPTION HANDLING in prograaming
PPTX
Exception Handling.pptx
PPTX
JAVA Presenttation topics Programs.pptx
PDF
Java unit 11
VTU MCA 2022 JAVA Exceeption Handling.docx
using Java Exception Handling in Java.pptx
Java Exception Handling & IO-Unit-3 (1).ppt
Exception handling in java
Lec-01 Exception Handling in Java_javatpoint.pptx
OBJECT ORIENTED PROGRAMMING_Unit3_NOTES first half.pptx
A36519192_21789_4_2018_Exception Handling.ppt
L14 exception handling
Exception handling in java.pptx
Java chapter 6
Exception Handling in JAVA
Chapter 5 Exception Handling (1).pdf
Java Exceptions and Exception Handling
presentationon exception handling in java.pptx
Exception Handling computer science concept java
Java_Exception-CheatSheet_Edureka.pdf
EXCEPTION HANDLING in prograaming
Exception Handling.pptx
JAVA Presenttation topics Programs.pptx
Java unit 11
Ad

More from chauhankapil (20)

PPTX
Gray level transformation
PPTX
Elements of visual perception
PPTX
JSP Client Request
PPTX
Jsp server response
PPTX
Markov decision process
PPTX
RNN basics in deep learning
PPTX
Introduction to generative adversarial networks (GANs)
PPTX
Bayesian probabilistic interference
PPTX
PPTX
Knowledge acquistion
PPTX
Knowledge based system
PPTX
Introduction of predicate logics
PPTX
Types of inheritance in java
PPTX
Representation of syntax, semantics and Predicate logics
PPTX
Inheritance in java
PPTX
Propositional logic
PPTX
Constructors in java
PPTX
Methods in java
PPT
Circular linked list
PPT
Doubly linked list
Gray level transformation
Elements of visual perception
JSP Client Request
Jsp server response
Markov decision process
RNN basics in deep learning
Introduction to generative adversarial networks (GANs)
Bayesian probabilistic interference
Knowledge acquistion
Knowledge based system
Introduction of predicate logics
Types of inheritance in java
Representation of syntax, semantics and Predicate logics
Inheritance in java
Propositional logic
Constructors in java
Methods in java
Circular linked list
Doubly linked list

Recently uploaded (20)

PDF
flutter Launcher Icons, Splash Screens & Fonts
PDF
Introduction to Data Science: data science process
PPTX
TE-AI-Unit VI notes using planning model
PPTX
web development for engineering and engineering
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
B.Tech (Electrical Engineering ) 2024 syllabus.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
PPTX
anatomy of limbus and anterior chamber .pptx
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PPTX
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Internship_Presentation_Final engineering.pptx
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PPT
Drone Technology Electronics components_1
PDF
Structs to JSON How Go Powers REST APIs.pdf
flutter Launcher Icons, Splash Screens & Fonts
Introduction to Data Science: data science process
TE-AI-Unit VI notes using planning model
web development for engineering and engineering
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Lesson 3_Tessellation.pptx finite Mathematics
B.Tech (Electrical Engineering ) 2024 syllabus.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Operating System & Kernel Study Guide-1 - converted.pdf
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
anatomy of limbus and anterior chamber .pptx
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Internship_Presentation_Final engineering.pptx
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
Drone Technology Electronics components_1
Structs to JSON How Go Powers REST APIs.pdf

Exception handling in java

  • 1. Exception Handling in Java Prof. Neeraj Bhargava Kapil Chauhan Department of Computer Science School of Engineering & Systems Sciences MDS University, Ajmer
  • 2. Exception Handling in Java  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.  An exception (or exceptional event) is a problem that arises during the execution of a program.
  • 3. What is Exception Handling  Exception Handling is a mechanism to handle runtime errors such as ClassNotFoundException, IOException, SQLException, RemoteException, etc.
  • 4. Types of Java Exceptions  There are mainly two types of exceptions: checked and unchecked. Here, an error is considered as the unchecked exception.  Checked Exception  Unchecked Exception
  • 5. Difference between Checked and Unchecked Exceptions  1) Checked Exception  The classes which directly inherit Throwable class except RuntimeException and Error are known as checked exceptions e.g. IOException, SQLException etc. Checked exceptions are checked at compile-time.
  • 6. Cont..  2) Unchecked Exception  The classes which inherit RuntimeException are known as unchecked exceptions e.g. ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. Unchecked exceptions are not checked at compile-time, but they are checked at runtime.
  • 7. Java Exception Keywords  Try  The "try" keyword is used to specify a block where we should place exception code. The try block must be followed by either catch or finally. It means, we can't use try block alone.  Catch  The "catch" block is used to handle the exception. It must be preceded by try block which means we can't use catch block alone. It can be followed by finally block later.
  • 8. Cont..  Finally  The "finally" block is used to execute the important code of the program. It is executed whether an exception is handled or not.  Throw  The "throw" keyword is used to throw an exception.
  • 9. Java Exception Handling Example  public class JavaExceptionExample{  public static void main(String args[]){  try{  //code that may raise exception  int data=100/0;  }catch(ArithmeticException e){System.out.println(e);}  //rest code of the program  System.out.println("rest of the code...");  }  }
  • 10. Assignment  Explain Exception handling in java with example.