SlideShare a Scribd company logo
1 of 9
S.Nandhini
II -MSc (CS&IT)
Nadar Saraswathi College Of Arts &Science
Theni
The purpose of exception handling mechanism is to provide a
means to detect and report an "exceptional circumstance" so
that appropriate action can be taken.
The mechanism suggests incorporation of a separate error
handling code that performs the following tasks:
1. Find the problem (Hit the exception).
2. Inform that an error has occurred (Throw
the exception)
3. Receive the error information (Catch the
exception)
4. Take corrective actions (Handle the
exception)
 An exception is a condition that is caused by a
run-time error in the program.
 When the Java interpreter encounters an error
such as dividing an integer by zero, it creates
an exception object and throws it(i.e., informs
us that an error has occurred).
EXCEPTION TYPE CAUSE OF EXCEPTION
ArithmeticException Caused by math errors such as division by
zero
ArraylndexOutOfBoundsException Caused by bad array indexes
ArrayStoreException to store the wrong type of data in an array
FileNotFoundException Caused by an attempt to access a nonexistent
file
(Continued)
StringIndexOutOfBoundsException Caused when a program attempts to access a
nonexistent character position in a string
StackOverflowException Caused when the system runs out of stack
space
NumberFormatException Caused when a conversion between strings
and number fails
..........
..........
try
{
statement; // generates an exception
}
catch (Exception type e)
{ statement; / / processes the exception
}
..........
..........
The try block can have one or more statements
that could generate an exception.
class Error3
{
public static void main (String args[ ] )
{
int a = 10; int b = 5; int c = 5; int x, y ;(Continued)
try
{
x = a I (b-c) ; // Exception here
}.
catch (ArithmeticException e)
{
System.out.println(“Division by zero");
}
y = a I (b+c) ;
System.out.println(u y = U + y);
}
}
output: Division by zero. y . = 1
 There may be times when we would like to throw our
own exceptions.
 SYNTAX
Examples:
 Throw new ArithmeticException( );
 Throw new NumberFormatException( );
The use of a user-defined subclass of Throwable class.
Note that Exception is a subclass of Throwable and
therefore MyException is a subclass of Throwable class.
Throw new throwable_subclass;
THANK YOU

More Related Content

What's hot

17 exception handling - ii
17 exception handling - ii17 exception handling - ii
17 exception handling - ii
Ravindra Rathore
 

What's hot (20)

Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in java
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Exception handling
Exception handlingException handling
Exception handling
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Built in exceptions
Built in exceptions Built in exceptions
Built in exceptions
 
Java Pitfalls and Good-to-Knows
Java Pitfalls and Good-to-KnowsJava Pitfalls and Good-to-Knows
Java Pitfalls and Good-to-Knows
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exceptions
ExceptionsExceptions
Exceptions
 
43c
43c43c
43c
 
Exceptions in python
Exceptions in pythonExceptions in python
Exceptions in python
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
17 exception handling - ii
17 exception handling - ii17 exception handling - ii
17 exception handling - ii
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
 
Python programming : Exceptions
Python programming : ExceptionsPython programming : Exceptions
Python programming : Exceptions
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 

Similar to exception handling in java

Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 
Exception Handling
Exception HandlingException Handling
Exception Handling
backdoor
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Prasad Sawant
 

Similar to exception handling in java (20)

1.12 Exception Handing.pptx
1.12 Exception Handing.pptx1.12 Exception Handing.pptx
1.12 Exception Handing.pptx
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Exception handling in java.pptx
Exception handling in java.pptxException handling in java.pptx
Exception handling in java.pptx
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
java exception.pptx
java exception.pptxjava exception.pptx
java exception.pptx
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exception Handling.pdf
Exception Handling.pdfException Handling.pdf
Exception Handling.pdf
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
 
Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024
 
Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024
 
Exception handling
Exception handlingException handling
Exception handling
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
 
Exception handling
Exception handlingException handling
Exception handling
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Satish training ppt
Satish training pptSatish training ppt
Satish training ppt
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 

More from Abinaya B

More from Abinaya B (17)

Multimedia
MultimediaMultimedia
Multimedia
 
Overview of bigdata
Overview of bigdataOverview of bigdata
Overview of bigdata
 
data structures
data structuresdata structures
data structures
 
graphics programming in java
graphics programming in javagraphics programming in java
graphics programming in java
 
data structures- back tracking
data structures- back trackingdata structures- back tracking
data structures- back tracking
 
digital image processing
digital image processingdigital image processing
digital image processing
 
Image filtering in Digital image processing
Image filtering in Digital image processingImage filtering in Digital image processing
Image filtering in Digital image processing
 
software engineering
software engineeringsoftware engineering
software engineering
 
software cost factor
software cost factorsoftware cost factor
software cost factor
 
Data Mining
Data MiningData Mining
Data Mining
 
Datamining
DataminingDatamining
Datamining
 
Basic topic on os
Basic topic on osBasic topic on os
Basic topic on os
 
Digital principles basic
Digital principles basicDigital principles basic
Digital principles basic
 
Rdbms1
Rdbms1Rdbms1
Rdbms1
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
 
Introduction to 80386
Introduction to 80386Introduction to 80386
Introduction to 80386
 
Network standardization
Network standardizationNetwork standardization
Network standardization
 

Recently uploaded

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

exception handling in java

  • 1. S.Nandhini II -MSc (CS&IT) Nadar Saraswathi College Of Arts &Science Theni
  • 2. The purpose of exception handling mechanism is to provide a means to detect and report an "exceptional circumstance" so that appropriate action can be taken. The mechanism suggests incorporation of a separate error handling code that performs the following tasks: 1. Find the problem (Hit the exception). 2. Inform that an error has occurred (Throw the exception) 3. Receive the error information (Catch the exception) 4. Take corrective actions (Handle the exception)
  • 3.  An exception is a condition that is caused by a run-time error in the program.  When the Java interpreter encounters an error such as dividing an integer by zero, it creates an exception object and throws it(i.e., informs us that an error has occurred).
  • 4. EXCEPTION TYPE CAUSE OF EXCEPTION ArithmeticException Caused by math errors such as division by zero ArraylndexOutOfBoundsException Caused by bad array indexes ArrayStoreException to store the wrong type of data in an array FileNotFoundException Caused by an attempt to access a nonexistent file (Continued) StringIndexOutOfBoundsException Caused when a program attempts to access a nonexistent character position in a string StackOverflowException Caused when the system runs out of stack space NumberFormatException Caused when a conversion between strings and number fails
  • 5. .......... .......... try { statement; // generates an exception } catch (Exception type e) { statement; / / processes the exception } .......... .......... The try block can have one or more statements that could generate an exception.
  • 6. class Error3 { public static void main (String args[ ] ) { int a = 10; int b = 5; int c = 5; int x, y ;(Continued) try { x = a I (b-c) ; // Exception here }. catch (ArithmeticException e) { System.out.println(“Division by zero"); } y = a I (b+c) ; System.out.println(u y = U + y); } } output: Division by zero. y . = 1
  • 7.
  • 8.  There may be times when we would like to throw our own exceptions.  SYNTAX Examples:  Throw new ArithmeticException( );  Throw new NumberFormatException( ); The use of a user-defined subclass of Throwable class. Note that Exception is a subclass of Throwable and therefore MyException is a subclass of Throwable class. Throw new throwable_subclass;