SlideShare a Scribd company logo
Java SE 11 Exception
Handling
BY: ASHWIN SHIV
NIT DELHI
Exception Handling
Introduction
 Exceptions in Java are any abnormal, unexpected events or extra-ordinary
conditions that may occur at runtime.
 Java Exception Handling is used to handle error conditions in a program
systemically by taking the necessary action.
 The java.lang.Throwable class and all its subclasses are collectively the
exception classes.
Class Hierarchy
Throwable has two subclasses: Exception and Error
What Happens when an Exception
occurs in a Java Program
 When an exception occurs, the method from which the exception
originated, creates a special object known as exception object and hands
it off to the Runtime System.
 The exception object contains information about the exception, and the
state of the program when the exception occurred.
 Creating an exception object and handing it to the runtime system is called
throwing an exception.
 You can manually throw an exception by identifying a scenario you
considered an exception, but in many cases, it is the Java Virtual
Machine(JVM) throwing exceptions manually
Searching the Call Stack for the
Exception Handler
try catch Clause
 If an exception occurs at the particular statement of try block,
the rest of the block code will not execute and code will fall
through to the catch statement.
 Syntax of try-catch:
 Unlike other statements such as if and else,the enclosing
braces {} sets are required in this case.
try catch finally clause
 The finally clause purpose is to clean up the resources.It will always get executed whether
an exception occurs in the try clause or not.
 You can declare a try-finally block also and you can also declare try-catch-finally together
also.
 What you cannot do is just declaring a try clause without a catch,or finally clause.It will
result in compiler error.
Declaring try-finally Declaring try-catch-finally
More on try-catch finally
 You can put a nested try-catch in outer try block or outer catch block or
outer finally block.
throw clause
 A program can explicitly throw an exception using the throw keyword besides the
implicit exception thrown.
 Syntax:
throws clause
 throws clause is used to declare an exception. It gives an information to
the programmer that there may occur an exception so it is better for the
programmer to provide the exception handling code so that normal flow
can be maintained.
 Syntax:
Unchecked Exceptions
 Unchecked Exceptions are those exceptions in which the compiler does
not force you to write code to check for the exception or specify the
exception.
 In other words, Unchecked Exceptions are those classes which inherit
RuntimeException.
 Eg: RuntimeException, ArithmeticException,
ArrayIndexOutOfBoundsException etc.
Unchecked Exceptions in Work
Output:
In this example,the program
abruptly ends as the exception is
not handled
Output
In this example,the program continues
after the exception has been caught
and handled by the catch clause so the
program will continue
Checked Exceptions
 A Checked Exception is a special designation, for a group of
exceptions that the compiler forces compliance of ‘The Catch
or Specify Requirement’.
 Catch or Specify Requirement: It states that code that might
throw certain exceptions, must be enclosed by either of the
following:
 A try statement that catches the exception. The try must provide an
appropriate handler for the exception.
 A method that specifies that it can throw Exception. The method must
provide a throws clause that lists the exception or an appropriate
exception type.
Checked Exceptions In Work
Output Output
In this example, the program abruptly
ends as the checked exception is not
handled.
In this example,the program continues
after the checked exception has been
caught and handled by the catch clause
so the program will continue.
Table to explain which Exceptions are
Checked or which are Unchecked
Thank You

More Related Content

PPT
Exception handling
PPT
exception handling
PDF
Best Practices in Exception Handling
PPT
Exception Handling Java
PPTX
7.error management and exception handling
PPT
Exception handling in java
PPT
12 exception handling
Exception handling
exception handling
Best Practices in Exception Handling
Exception Handling Java
7.error management and exception handling
Exception handling in java
12 exception handling

What's hot (20)

PPTX
Exceptionhandling
PPSX
Exception Handling
PPT
Exceptions in java
PPTX
Exception handling in java
PPT
C# Exceptions Handling
PDF
Exception Handling in Java
PPTX
Presentation on-exception-handling
PPTX
Exception handling in java
DOCX
Java Exception handling
PPTX
Exception handling in java
PPTX
Exception handling in java
PPTX
Exception handling
PPTX
Exceptional Handling in Java
PPTX
Exception Handling in C++
PDF
Java review: try catch
PDF
Java - Exception Handling Concepts
DOCX
Exceptions handling notes in JAVA
PPTX
Exception Handling in Java
PPT
Week7 exception handling
PDF
summarizer16fev16_Exceptions
Exceptionhandling
Exception Handling
Exceptions in java
Exception handling in java
C# Exceptions Handling
Exception Handling in Java
Presentation on-exception-handling
Exception handling in java
Java Exception handling
Exception handling in java
Exception handling in java
Exception handling
Exceptional Handling in Java
Exception Handling in C++
Java review: try catch
Java - Exception Handling Concepts
Exceptions handling notes in JAVA
Exception Handling in Java
Week7 exception handling
summarizer16fev16_Exceptions
Ad

Similar to Java SE 11 Exception Handling (20)

PPT
Exceptionhandling
PPTX
Java Exceptions and Exception Handling
PPTX
130410107010 exception handling
PDF
Ch-1_5.pdf this is java tutorials for all
PDF
Exception handling
PPTX
Exception Handling in Java
DOCX
Class notes(week 8) on exception handling
PPTX
Exception handling
PDF
Class notes(week 8) on exception handling
PPT
A36519192_21789_4_2018_Exception Handling.ppt
PPTX
Chap2 exception handling
PPTX
Java-Unit 3- Chap2 exception handling
PDF
Java unit 11
PPTX
L14 exception handling
PPTX
Java-Exception Handling Presentation. 2024
PPTX
Exception Handling In Java Presentation. 2024
PPT
Exception handling
PPTX
Interface andexceptions
PPTX
Exception Handling.pptx
Exceptionhandling
Java Exceptions and Exception Handling
130410107010 exception handling
Ch-1_5.pdf this is java tutorials for all
Exception handling
Exception Handling in Java
Class notes(week 8) on exception handling
Exception handling
Class notes(week 8) on exception handling
A36519192_21789_4_2018_Exception Handling.ppt
Chap2 exception handling
Java-Unit 3- Chap2 exception handling
Java unit 11
L14 exception handling
Java-Exception Handling Presentation. 2024
Exception Handling In Java Presentation. 2024
Exception handling
Interface andexceptions
Exception Handling.pptx
Ad

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Approach and Philosophy of On baking technology
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
KodekX | Application Modernization Development
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Approach and Philosophy of On baking technology
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
Advanced methodologies resolving dimensionality complications for autism neur...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Cloud computing and distributed systems.
Encapsulation_ Review paper, used for researhc scholars
Understanding_Digital_Forensics_Presentation.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
20250228 LYD VKU AI Blended-Learning.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation

Java SE 11 Exception Handling

  • 1. Java SE 11 Exception Handling BY: ASHWIN SHIV NIT DELHI
  • 3. Introduction  Exceptions in Java are any abnormal, unexpected events or extra-ordinary conditions that may occur at runtime.  Java Exception Handling is used to handle error conditions in a program systemically by taking the necessary action.  The java.lang.Throwable class and all its subclasses are collectively the exception classes.
  • 4. Class Hierarchy Throwable has two subclasses: Exception and Error
  • 5. What Happens when an Exception occurs in a Java Program  When an exception occurs, the method from which the exception originated, creates a special object known as exception object and hands it off to the Runtime System.  The exception object contains information about the exception, and the state of the program when the exception occurred.  Creating an exception object and handing it to the runtime system is called throwing an exception.  You can manually throw an exception by identifying a scenario you considered an exception, but in many cases, it is the Java Virtual Machine(JVM) throwing exceptions manually
  • 6. Searching the Call Stack for the Exception Handler
  • 7. try catch Clause  If an exception occurs at the particular statement of try block, the rest of the block code will not execute and code will fall through to the catch statement.  Syntax of try-catch:  Unlike other statements such as if and else,the enclosing braces {} sets are required in this case.
  • 8. try catch finally clause  The finally clause purpose is to clean up the resources.It will always get executed whether an exception occurs in the try clause or not.  You can declare a try-finally block also and you can also declare try-catch-finally together also.  What you cannot do is just declaring a try clause without a catch,or finally clause.It will result in compiler error. Declaring try-finally Declaring try-catch-finally
  • 9. More on try-catch finally  You can put a nested try-catch in outer try block or outer catch block or outer finally block.
  • 10. throw clause  A program can explicitly throw an exception using the throw keyword besides the implicit exception thrown.  Syntax:
  • 11. throws clause  throws clause is used to declare an exception. It gives an information to the programmer that there may occur an exception so it is better for the programmer to provide the exception handling code so that normal flow can be maintained.  Syntax:
  • 12. Unchecked Exceptions  Unchecked Exceptions are those exceptions in which the compiler does not force you to write code to check for the exception or specify the exception.  In other words, Unchecked Exceptions are those classes which inherit RuntimeException.  Eg: RuntimeException, ArithmeticException, ArrayIndexOutOfBoundsException etc.
  • 13. Unchecked Exceptions in Work Output: In this example,the program abruptly ends as the exception is not handled Output In this example,the program continues after the exception has been caught and handled by the catch clause so the program will continue
  • 14. Checked Exceptions  A Checked Exception is a special designation, for a group of exceptions that the compiler forces compliance of ‘The Catch or Specify Requirement’.  Catch or Specify Requirement: It states that code that might throw certain exceptions, must be enclosed by either of the following:  A try statement that catches the exception. The try must provide an appropriate handler for the exception.  A method that specifies that it can throw Exception. The method must provide a throws clause that lists the exception or an appropriate exception type.
  • 15. Checked Exceptions In Work Output Output In this example, the program abruptly ends as the checked exception is not handled. In this example,the program continues after the checked exception has been caught and handled by the catch clause so the program will continue.
  • 16. Table to explain which Exceptions are Checked or which are Unchecked