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
Ad

More Related Content

What's hot (20)

Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
Nuha Noor
 
Exception Handling
Exception HandlingException Handling
Exception Handling
Reddhi Basu
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
Manav Prasad
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
Elizabeth alexander
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
sharqiyem
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
Java2Blog
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
Nahian Ahmed
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
yugandhar vadlamudi
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
Garuda Trainings
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
pooja kumari
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Kavitha713564
 
Exception handling
Exception handlingException handling
Exception handling
PhD Research Scholar
 
Exceptional Handling in Java
Exceptional Handling in JavaExceptional Handling in Java
Exceptional Handling in Java
QaziUmarF786
 
Exception Handling in C++
Exception Handling in C++Exception Handling in C++
Exception Handling in C++
Deepak Tathe
 
Java review: try catch
Java review: try catchJava review: try catch
Java review: try catch
Muzahidul Islam
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
Victer Paul
 
Exceptions handling notes in JAVA
Exceptions handling notes in JAVAExceptions handling notes in JAVA
Exceptions handling notes in JAVA
Sunil Kumar Gunasekaran
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
Ganesh kumar reddy
 
Week7 exception handling
Week7 exception handlingWeek7 exception handling
Week7 exception handling
Alpesh Oza
 
summarizer16fev16_Exceptions
summarizer16fev16_Exceptionssummarizer16fev16_Exceptions
summarizer16fev16_Exceptions
Filipe Morais Jorge
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
Nuha Noor
 
Exception Handling
Exception HandlingException Handling
Exception Handling
Reddhi Basu
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
Manav Prasad
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
sharqiyem
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
Java2Blog
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
Nahian Ahmed
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
pooja kumari
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Kavitha713564
 
Exceptional Handling in Java
Exceptional Handling in JavaExceptional Handling in Java
Exceptional Handling in Java
QaziUmarF786
 
Exception Handling in C++
Exception Handling in C++Exception Handling in C++
Exception Handling in C++
Deepak Tathe
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
Victer Paul
 
Week7 exception handling
Week7 exception handlingWeek7 exception handling
Week7 exception handling
Alpesh Oza
 

Similar to Java SE 11 Exception Handling (20)

Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
DrHemlathadhevi
 
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
poongothai11
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
saman Iftikhar
 
Exception Handling in java masters of computer application
Exception Handling in java masters of computer applicationException Handling in java masters of computer application
Exception Handling in java masters of computer application
xidileh999
 
Module 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptx
Module 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptxModule 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptx
Module 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptx
mcaajiet25
 
Exception handling
Exception handlingException handling
Exception handling
Tata Consultancy Services
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
Shipra Swati
 
Exception handling basic
Exception handling basicException handling basic
Exception handling basic
TharuniDiddekunta
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
AKSHAYBHABAD5
 
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
SakkaravarthiS1
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
primevideos176
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
EduclentMegasoftel
 
exceptions in java
exceptions in javaexceptions in java
exceptions in java
javeed_mhd
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertion
Rakesh Madugula
 
Java Exception.ppt
Java Exception.pptJava Exception.ppt
Java Exception.ppt
RanjithaM32
 
Exception Handling,finally,catch,throw,throws,try.pptx
Exception Handling,finally,catch,throw,throws,try.pptxException Handling,finally,catch,throw,throws,try.pptx
Exception Handling,finally,catch,throw,throws,try.pptx
ArunPatrick2
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
pooja kumari
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
Bharath K
 
MODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docxMODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docx
VeerannaKotagi1
 
Unit5 java
Unit5 javaUnit5 java
Unit5 java
mrecedu
 
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
poongothai11
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
saman Iftikhar
 
Exception Handling in java masters of computer application
Exception Handling in java masters of computer applicationException Handling in java masters of computer application
Exception Handling in java masters of computer application
xidileh999
 
Module 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptx
Module 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptxModule 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptx
Module 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptx
mcaajiet25
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
AKSHAYBHABAD5
 
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
SakkaravarthiS1
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
primevideos176
 
exceptions in java
exceptions in javaexceptions in java
exceptions in java
javeed_mhd
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertion
Rakesh Madugula
 
Java Exception.ppt
Java Exception.pptJava Exception.ppt
Java Exception.ppt
RanjithaM32
 
Exception Handling,finally,catch,throw,throws,try.pptx
Exception Handling,finally,catch,throw,throws,try.pptxException Handling,finally,catch,throw,throws,try.pptx
Exception Handling,finally,catch,throw,throws,try.pptx
ArunPatrick2
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
pooja kumari
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
Bharath K
 
MODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docxMODULE5_EXCEPTION HANDLING.docx
MODULE5_EXCEPTION HANDLING.docx
VeerannaKotagi1
 
Unit5 java
Unit5 javaUnit5 java
Unit5 java
mrecedu
 
Ad

Recently uploaded (20)

UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
AI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdfAI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdf
Precisely
 
Financial Services Technology Summit 2025
Financial Services Technology Summit 2025Financial Services Technology Summit 2025
Financial Services Technology Summit 2025
Ray Bugg
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
BookNet Canada
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
AI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdfAI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdf
Precisely
 
Financial Services Technology Summit 2025
Financial Services Technology Summit 2025Financial Services Technology Summit 2025
Financial Services Technology Summit 2025
Ray Bugg
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
BookNet Canada
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Ad

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
  翻译: