SlideShare a Scribd company logo
exception handling in java.ppt
OBJECT ORIENTED PROGRAMMING
18ITC203JD - 2ND YEAR
GUIDED BY
MRS.R.SUJATHA
T H A N U S H R E E K S
( 9 2 7 6 2 1 B I T 1 1 6 )
VA R S H I N I L
( 9 2 7 6 2 1 B I T 1 2 2 )
R A J A L A K S H M I S
( 9 2 7 6 2 1 B I T 0 8 8 )
EXPECTION HANDLING IN
JAVA
EXCEPTION
HANDLING
The exception
handling in java is
one of the powerful
Mechanism to handle
the routine events.
exception handling in java.ppt
EXCEPTION:
IOEXCEPTION
Compilation time of program.
SQLEXCEPTION:
Provides information on a database access errors.
CLASSNOTFOUNDEXCEPTION:
Try to load a class at runtime using class.
RUNTIMEEXCEPTION:
Superclass of those exceptions that can be thrown
during the normal operation.
STACKOVERFLOWERROR:
Application stack is exhausted.
VIRTUALMACHINEERROR:
It is broken or has run out of resources.
OUTOFMEMORYERROR:
It is thrown when there is insufficient space
to allocate an object.
ERROR
ARITHMETIC EXCEPTION:
It is unchecked exception.
NULL POINTER EXCEPTION:
AVariable is accessed which is not pointing
to any object.
NUMBER FORMAT EXCEPTION:
It occurs when an attempt to convert to a
string.
INDEX OUT OF BOUND EXCEPTION:
It occurs attempt to access the character of a
string.
RUNTIME
EXCEPTION
ARRAYINDEXOUTOFBOUNDEXCEPTION:
To access an invalid index in an array.
STRAIGHT-INDEXOUTOFBOUNDEXCEPTION:
To access the character of a string at an index.
INDEX OUT OF BOUND EXCEPTION:
TYPES OF EXCEPTION IN
JAVA:
• There are mainly two types of exceptions:
• checked and unchecked.
• An error is considered as the unchecked
exception.
• However, according to Oracle, there are
three types of exceptions namely:
• Checked Exception
• Unchecked Exception
• Error Exception
• CHECKED EXCEPTION:
Exceptions that can be checked compile time it is checked
exception.
EG: IO Exception, SQL Exception.
• UNCHECKED EXCEPTION:
Exception that can be checked at run time it is called unchecked
exception.
EG: Arithmetic Exception, Null pointerException.
•Error can be included in unchecked exception.
EG: Out of memory error, virtual machine error.
• Error is Incoverable.
JAVA EXCEPTION KEYWORDS:
There are five major keywords
which is used as the keywords in
the java Exception. They are,
Try
Catch
Finally
Throw
Throws
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.
SYNTAX:
try {
// Block of code to try
}
catch(Exception e) {
// Block of code to handle errors
}
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.
The catch statement allows you to
define a block of code to be
executed, if an error occurs in thetry
block.
FINALLY
:
•The "finally" block is used to execute the necessary
code of the program.
•The finally keyword is used to execute code no
matter if there is an exception or not.
•If you don't handle the exception, before
terminating the program, JVM executes finally
block.
THROW:
• The "throw" keyword is used to throw an
exception.
• The throw keyword is used to create a
custom error. The throw statement is used
together with an exception type. There
are many exception types available in
Java.
• EG:
Arithmetic Exception , Class Not Found
Exception
, ArrayIndexOutOfBoundsE
xception , Security Exception , etc.
THROWS:
The throws keyword is used to declare which exceptions can be thrown
from a method, while the throw keyword is used to explicitly throw an
exception within a method or block of code.
It doesn't throw an exception.
It is always used with method signature.
Its syntax is:
accessModifier returnType methodName()
throws ExceptionType1, ExceptionType2 … {
// code
}
JAVA EXCEPTIONS
INDEX:
• Java Try-Catch Block
• Java Multiple Catch Block
• Java Nested Try
• Java Finally Block
• Java Throw Keyword
• Java Exception Propagation
• Java Throws Keyword
• Java Throw vs Throws
• Java Final vs Finally vs Finalize
• Java Exception Handling with Method Overriding
• Java Custom Exceptions
JAVA
TRY
BLOCK
• Java try block is used to enclose the
code that might throw an exception. It
must be used within the method.
• If an exception occurs at the particular
statement in the try block, the rest of
the block code will not execute. So, it
is recommended not to keep the code
in try block that will not throw an
exception.
• Java try block must be followed by
either catch or finally block.
JAVA TRY-CATCH BLOCK
:
•Java catch block is used to handle the Exceptionby declaring the type of
exception within the parameter. The declared exception must be the
parent class exception ( i.e., Exception) or the generated exception type.
However, the good approach is to declare the generated type of exception.
•SYNTAX:
•try{
•//code that may throw an exception
•}finally{}
JAVA
CATCH
MULTIPLE
EXCEPTIO
NS:
Java Multi-catch block:
•A try block can be followed by one or more catch
blocks. Each catch block must contain a different
exception handler. So, if you have to perform
different tasks at the occurrence of different
exceptions, use java multi-catch block.
Points to remember:
• At a time only one exception occurs and at a
time
only one catch block is executed.
• All catch blocks must be ordered from most
specific to most general, i.e. catch for
Arithmetic Exception must come before catch
for Exception.
JAVA
FINALL
Y
BLOCK:
•Java finally block is a block used to execute
important code such as closing the connection,
etc.
•Java finally block is always executed whether
an exception is handled or not. Therefore, it
contains all the necessary statements that need
to be printed regardless of
the exception occurs or not.
• The finally block follows the try-catch block.
JAVA
THROW
EXCEPTION:
• In Java, exceptions allows us to write good
quality codes where the errors are checked at
the compile time instead of runtime and we
can create custom exceptions making the
code recovery and debugging easier.
• Java throw keyword
• The Java throw keyword is used to throw an
exception explicitly.
• We specify the exception object which is to
be thrown. The Exception has some message
with it that provides the error
description. These exceptions may be related
to user inputs, server, etc.
exception handling in java.ppt

More Related Content

What's hot (20)

PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
ODP
OOP java
xball977
 
PPTX
Inner classes in java
PhD Research Scholar
 
PPTX
Arrays in Java
Abhilash Nair
 
PPT
Final keyword in java
Lovely Professional University
 
PPTX
Classes objects in java
Madishetty Prathibha
 
PPTX
Nested loops
Neeru Mittal
 
PPTX
Exception Handling in Java
lalithambiga kamaraj
 
PPTX
Methods in java
chauhankapil
 
PPTX
Java Data Types
Spotle.ai
 
PPTX
This keyword in java
Hitesh Kumar
 
PPTX
Access specifiers(modifiers) in java
HrithikShinde
 
PPTX
Constructor in java
Pavith Gunasekara
 
PDF
Files in java
Muthukumaran Subramanian
 
PPT
Inheritance in java
Lovely Professional University
 
PDF
Java threads
Prabhakaran V M
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
PPTX
Inheritance in java
RahulAnanda1
 
PPTX
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
PDF
Class and Objects in Java
Spotle.ai
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
OOP java
xball977
 
Inner classes in java
PhD Research Scholar
 
Arrays in Java
Abhilash Nair
 
Final keyword in java
Lovely Professional University
 
Classes objects in java
Madishetty Prathibha
 
Nested loops
Neeru Mittal
 
Exception Handling in Java
lalithambiga kamaraj
 
Methods in java
chauhankapil
 
Java Data Types
Spotle.ai
 
This keyword in java
Hitesh Kumar
 
Access specifiers(modifiers) in java
HrithikShinde
 
Constructor in java
Pavith Gunasekara
 
Inheritance in java
Lovely Professional University
 
Java threads
Prabhakaran V M
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
Inheritance in java
RahulAnanda1
 
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
Class and Objects in Java
Spotle.ai
 

Similar to exception handling in java.ppt (20)

PPTX
UNIT 2.pptx
EduclentMegasoftel
 
PPTX
UNIT III 2021R.pptx
RDeepa9
 
PPTX
UNIT III 2021R.pptx
RDeepa9
 
PPTX
Exception handling in java
pooja kumari
 
PPTX
Exception handling in java
pooja kumari
 
PPTX
Exception handling in java.pptx
Nagaraju Pamarthi
 
PPTX
Exceptions handling in java
junnubabu
 
PPTX
Exception Handling.pptx
primevideos176
 
PDF
Java exceptions
Pawan Kumar
 
PPTX
Exception handling
Ardhendu Nandi
 
PPTX
java exception.pptx
SukhpreetSingh519414
 
PDF
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 
PPT
oop-unit-iii-ppt.pptexceptionhandlingobjectorientedprogramming
ssuserf45a65
 
PPTX
Chap2 exception handling
raksharao
 
PPTX
Java-Unit 3- Chap2 exception handling
raksharao
 
PPTX
Exception handling in java
Kavitha713564
 
PPT
Java exception
Arati Gadgil
 
PDF
JAVA PPT -4 BY ADI.pdf
Prof. Dr. K. Adisesha
 
PPTX
Java exception handling
BHUVIJAYAVELU
 
PPTX
Unit 4 exceptions and threads
DevaKumari Vijay
 
UNIT 2.pptx
EduclentMegasoftel
 
UNIT III 2021R.pptx
RDeepa9
 
UNIT III 2021R.pptx
RDeepa9
 
Exception handling in java
pooja kumari
 
Exception handling in java
pooja kumari
 
Exception handling in java.pptx
Nagaraju Pamarthi
 
Exceptions handling in java
junnubabu
 
Exception Handling.pptx
primevideos176
 
Java exceptions
Pawan Kumar
 
Exception handling
Ardhendu Nandi
 
java exception.pptx
SukhpreetSingh519414
 
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 
oop-unit-iii-ppt.pptexceptionhandlingobjectorientedprogramming
ssuserf45a65
 
Chap2 exception handling
raksharao
 
Java-Unit 3- Chap2 exception handling
raksharao
 
Exception handling in java
Kavitha713564
 
Java exception
Arati Gadgil
 
JAVA PPT -4 BY ADI.pdf
Prof. Dr. K. Adisesha
 
Java exception handling
BHUVIJAYAVELU
 
Unit 4 exceptions and threads
DevaKumari Vijay
 
Ad

Recently uploaded (20)

PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Horarios de distribución de agua en julio
pegazohn1978
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Difference between write and update in odoo 18
Celine George
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
infertility, types,causes, impact, and management
Ritu480198
 
Ad

exception handling in java.ppt

  • 3. GUIDED BY MRS.R.SUJATHA T H A N U S H R E E K S ( 9 2 7 6 2 1 B I T 1 1 6 ) VA R S H I N I L ( 9 2 7 6 2 1 B I T 1 2 2 ) R A J A L A K S H M I S ( 9 2 7 6 2 1 B I T 0 8 8 )
  • 5. EXCEPTION HANDLING The exception handling in java is one of the powerful Mechanism to handle the routine events.
  • 7. EXCEPTION: IOEXCEPTION Compilation time of program. SQLEXCEPTION: Provides information on a database access errors. CLASSNOTFOUNDEXCEPTION: Try to load a class at runtime using class. RUNTIMEEXCEPTION: Superclass of those exceptions that can be thrown during the normal operation.
  • 8. STACKOVERFLOWERROR: Application stack is exhausted. VIRTUALMACHINEERROR: It is broken or has run out of resources. OUTOFMEMORYERROR: It is thrown when there is insufficient space to allocate an object. ERROR
  • 9. ARITHMETIC EXCEPTION: It is unchecked exception. NULL POINTER EXCEPTION: AVariable is accessed which is not pointing to any object. NUMBER FORMAT EXCEPTION: It occurs when an attempt to convert to a string. INDEX OUT OF BOUND EXCEPTION: It occurs attempt to access the character of a string. RUNTIME EXCEPTION
  • 10. ARRAYINDEXOUTOFBOUNDEXCEPTION: To access an invalid index in an array. STRAIGHT-INDEXOUTOFBOUNDEXCEPTION: To access the character of a string at an index. INDEX OUT OF BOUND EXCEPTION:
  • 11. TYPES OF EXCEPTION IN JAVA: • There are mainly two types of exceptions: • checked and unchecked. • An error is considered as the unchecked exception. • However, according to Oracle, there are three types of exceptions namely: • Checked Exception • Unchecked Exception • Error Exception
  • 12. • CHECKED EXCEPTION: Exceptions that can be checked compile time it is checked exception. EG: IO Exception, SQL Exception. • UNCHECKED EXCEPTION: Exception that can be checked at run time it is called unchecked exception. EG: Arithmetic Exception, Null pointerException. •Error can be included in unchecked exception. EG: Out of memory error, virtual machine error. • Error is Incoverable.
  • 13. JAVA EXCEPTION KEYWORDS: There are five major keywords which is used as the keywords in the java Exception. They are, Try Catch Finally Throw Throws
  • 14. 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. SYNTAX: try { // Block of code to try } catch(Exception e) { // Block of code to handle errors }
  • 15. 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. The catch statement allows you to define a block of code to be executed, if an error occurs in thetry block.
  • 16. FINALLY : •The "finally" block is used to execute the necessary code of the program. •The finally keyword is used to execute code no matter if there is an exception or not. •If you don't handle the exception, before terminating the program, JVM executes finally block.
  • 17. THROW: • The "throw" keyword is used to throw an exception. • The throw keyword is used to create a custom error. The throw statement is used together with an exception type. There are many exception types available in Java. • EG: Arithmetic Exception , Class Not Found Exception , ArrayIndexOutOfBoundsE xception , Security Exception , etc.
  • 18. THROWS: The throws keyword is used to declare which exceptions can be thrown from a method, while the throw keyword is used to explicitly throw an exception within a method or block of code. It doesn't throw an exception. It is always used with method signature. Its syntax is: accessModifier returnType methodName() throws ExceptionType1, ExceptionType2 … { // code }
  • 19. JAVA EXCEPTIONS INDEX: • Java Try-Catch Block • Java Multiple Catch Block • Java Nested Try • Java Finally Block • Java Throw Keyword • Java Exception Propagation • Java Throws Keyword • Java Throw vs Throws • Java Final vs Finally vs Finalize • Java Exception Handling with Method Overriding • Java Custom Exceptions
  • 20. JAVA TRY BLOCK • Java try block is used to enclose the code that might throw an exception. It must be used within the method. • If an exception occurs at the particular statement in the try block, the rest of the block code will not execute. So, it is recommended not to keep the code in try block that will not throw an exception. • Java try block must be followed by either catch or finally block.
  • 21. JAVA TRY-CATCH BLOCK : •Java catch block is used to handle the Exceptionby declaring the type of exception within the parameter. The declared exception must be the parent class exception ( i.e., Exception) or the generated exception type. However, the good approach is to declare the generated type of exception. •SYNTAX: •try{ •//code that may throw an exception •}finally{}
  • 22. JAVA CATCH MULTIPLE EXCEPTIO NS: Java Multi-catch block: •A try block can be followed by one or more catch blocks. Each catch block must contain a different exception handler. So, if you have to perform different tasks at the occurrence of different exceptions, use java multi-catch block. Points to remember: • At a time only one exception occurs and at a time only one catch block is executed. • All catch blocks must be ordered from most specific to most general, i.e. catch for Arithmetic Exception must come before catch for Exception.
  • 23. JAVA FINALL Y BLOCK: •Java finally block is a block used to execute important code such as closing the connection, etc. •Java finally block is always executed whether an exception is handled or not. Therefore, it contains all the necessary statements that need to be printed regardless of the exception occurs or not. • The finally block follows the try-catch block.
  • 24. JAVA THROW EXCEPTION: • In Java, exceptions allows us to write good quality codes where the errors are checked at the compile time instead of runtime and we can create custom exceptions making the code recovery and debugging easier. • Java throw keyword • The Java throw keyword is used to throw an exception explicitly. • We specify the exception object which is to be thrown. The Exception has some message with it that provides the error description. These exceptions may be related to user inputs, server, etc.