0% found this document useful (0 votes)
16 views10 pages

Oops

The document provides an overview of exception handling in Java, defining it as a mechanism to manage runtime errors to maintain normal program flow. It categorizes exceptions into checked and unchecked types, explains the hierarchy of Java exceptions, and introduces keywords such as try, catch, finally, throw, and throws. The document emphasizes the importance of exception handling in preventing program crashes due to unexpected events.

Uploaded by

nikhildeutsch03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views10 pages

Oops

The document provides an overview of exception handling in Java, defining it as a mechanism to manage runtime errors to maintain normal program flow. It categorizes exceptions into checked and unchecked types, explains the hierarchy of Java exceptions, and introduces keywords such as try, catch, finally, throw, and throws. The document emphasizes the importance of exception handling in preventing program crashes due to unexpected events.

Uploaded by

nikhildeutsch03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Exception

handling
Agenda
What is exception handling
Types of exception handling
Hierarchy of java exceptions
Java exception and keywords
Exception Names and descriptions
What is exception
handling
Exception handling is the process of responding to
unwanted or unexpected events when a computer program
runs.
Exception Handling is a mechanism to handle runtime
errors such as ClassNotFoundException, IOException,
SQLException, RemoteException, etc.
Exception handling deals with these events to avoid the
program or system crashing, and without this process,
exceptions would disrupt the normal operation of a
program.
In Java, an exception is an event that disrupts the normal
flow of the program. It is an object which is thrown at
runtime.
The core advantage of exception handling is to maintain
the normal flow of the application.
Types of exception
handling
There are two types of Exceptions:
1)Checked Exception:
The classes that directly inherit the Throwable class
except RuntimeException and Error are known as
checked exceptions. For example, IOException,
SQLException, etc. Checked exceptions are checked at
compile-time.
2) Unchecked Exception:
The classes that inherit the RuntimeException are
known as unchecked exceptions. For example,
ArithmeticException, NullPointerException,
ArrayIndexOutOfBoundsException, etc. Unchecked
exceptions are not checked at compile-time, but they
are checked at runtime.
Hierarchy of java
exceptions
All exception and error types are subclasses
of the class Throwable, which is the base
class of the hierarchy. One branch is headed
by Exception. This class is used for
exceptional conditions that user programs
should catch. NullPointerException is an
example of such an exception. Another
branch, Error is used by the Java run-time
system(JVM) to indicate errors having to do
with the run-time environment itself(JRE).
StackOverflowError is an example of such an
error.
Java exceptions hierarchy
Java Exceptions
and keywords
1)Try:
The "try" keyword is used to specify a block
where we should place an exception code. It
means we can't use try block alone. The try
block must be followed by either catch or
finally.
2)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.
Java exceptions
and keywords
3)Finally:
The "finally" block is used to execute the necessary
code of the program. It is executed whether an
exception is handled or not
4)Throw:
The "throw" keyword is used to throw an
exception.
5)Throws:
The "throws" keyword is used to declare
exceptions. It specifies that there may occur an
exception in the method. It doesn't throw an
exception. It is always used with method signature.
Exception names and their
descriptions
Example program

You might also like