SlideShare a Scribd company logo
1 of 14
EXCEPTION
HANDLING
Submitted by
D.Shanmugapriya
II-Msc(IT)
Department of CS & IT
Nadar Saraswathi college of Arts & Science
Theni.
Contents
• Errors and Exception
• Exception Handling Mechanism
• Try,catch and throw
• Re-throwing an exception
• Specifying Exceptions
What is an Error?
• An Error is a term used to describe any issue that arises unexpectedly and
results in incorrect output
What are the Different types of errors?
Logical error:
• Occur due to poor understanding of problem or solution procedure.
Syntatic error:
• Arise due to poor understanding of the language itself.
What is an exception?
• Exception are runtime anomalies or unusual conditions that a program may
encounter while executing.
Exception Handling
• Exceptions are of two types:
• Synchronous exceptions
• The exceptions which occur during the program execution due to some
fault in the input data are known as synchronous exceptions.
• For example:errors such as out of range, overflow,underflow.
• Asynchronous exceptions
• The exceptions caused by events or faults unrelated to the program and
beyond the control of the program are called asynchronous exceptions.
• Example:errors such as keyboard interrupts hardware
malfunctions,disk failure.
Exception Handling Mechanism
• Exception handling Mechanism provides a means to
detect and report an exception circumstances.
• Find the problem (hit the exception)
• Inform that an Error has occurred (throw the exception)
• Receive the error information (catch the exception)
• Take corrective Actions(handle the exception)
Types of Exception Handling
• The exception handling mechanism is bulit upon three keywords:
• TRY
• Is used to perface a block of statements which may generate exception.
• THROW
• When an exception is detected,it is thrown using a throw statement in the try
block.
• CATCH
• A catch block defined by the keyword catch catches the exception thrown by
the throw statement in the try block and handles it appropriately.
Exception thrown by functions
• Int main()
• {
• Try
• {
• Divide(10,20,30);
• Divide (10,10,20);
• }
• Catch(int I)
• {
• Cout <<“n exception caught”;
• }
• Return 0;
1.Throw point
Function that causes an
exception
2.Try block
Invokes a function that
contains an exception
3.Catch block
Catches and handles the
exception
Throwing mechanism
• When an exception is desired to be handled is detected,it
is thrown using the throw statement.
• Throw statement has one of the following forms:
• Throw (exception)
• Throw exception
• Throw;
• The operand object exception may be of any type,
including constants.
Multiple catch statements
• Multiple catch statements can be associated with a try
block.
• When an exception is thrown,the exception handlers are
searched for an appropriate match.
• The first handler that yields the match is executed.
• After executed the handler,the controls goes to the first
statement after the last catch block for that try.
Multiple catch statements
Int main()
{
Cout<<“n x ==1”;
Test(1);
Cout<<“n x==0”;
Test(0);
Cout<<“n x==-1”;
Test(-1);
Cout<<“n x==2”;
Test(2);
Return 0;
}
Catching mechanism
• The type indicates the type of exception that catch block
handles.
• The catch statement catches an exception whose type
matches with the type of catch argument.
A catch block like a function definition
Catch(type arg)
{
//Statements for managing exceptions.
}
Catch all Exception
• A catch statement can also force to catch all Exception instead of a
certain type alone.
• Int main()
• {
• Cout<<“n testing generic catch”;
• Test(1);
• Test(0);
• Test(-1);
• Test(2);
• Return 0;
• }
Re-throwing exception
• A handler can rethrow the exception caught without
processing it.
• This can be done using throw without any argument.
• Here the current exception is thrown to the next enclosing
try/catch block.
• Every time when an exception is re-thrown it will not be
caught by the same catch statements rather it will be
caught by the catch statement outside the try catch block.
Thank you

More Related Content

What's hot

Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
Vadym Lotar
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Raghu nath
 
Exception handling
Exception handlingException handling
Exception handling
Iblesoft
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 

What's hot (20)

Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Java IO
Java IOJava IO
Java IO
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
Exception handling
Exception handlingException handling
Exception handling
 
Features of java
Features of javaFeatures of java
Features of java
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
 
Exception handling in .net
Exception handling in .netException handling in .net
Exception handling in .net
 

Similar to exception handling

Java class 7
Java class 7Java class 7
Java class 7
Edureka!
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
AboMohammad10
 

Similar to exception handling (20)

Exceptions in C++ Object Oriented Programming.pptx
Exceptions in C++ Object Oriented Programming.pptxExceptions in C++ Object Oriented Programming.pptx
Exceptions in C++ Object Oriented Programming.pptx
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exceptionn
ExceptionnExceptionn
Exceptionn
 
Unit 5
Unit 5Unit 5
Unit 5
 
Exception handling in java.pptx
Exception handling in java.pptxException handling in java.pptx
Exception handling in java.pptx
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
java.pptx
java.pptxjava.pptx
java.pptx
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
16 exception handling - i
16 exception handling - i16 exception handling - i
16 exception handling - i
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handling
 
Java class 7
Java class 7Java class 7
Java class 7
 
Unit iii pds
Unit iii pdsUnit iii pds
Unit iii pds
 
A36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.pptA36519192_21789_4_2018_Exception Handling.ppt
A36519192_21789_4_2018_Exception Handling.ppt
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
 
Pi j4.2 software-reliability
Pi j4.2 software-reliabilityPi j4.2 software-reliability
Pi j4.2 software-reliability
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 

More from rajshreemuthiah (20)

oracle
oracleoracle
oracle
 
quality
qualityquality
quality
 
bigdata
bigdatabigdata
bigdata
 
polymorphism
polymorphismpolymorphism
polymorphism
 
solutions and understanding text analytics
solutions and understanding text analyticssolutions and understanding text analytics
solutions and understanding text analytics
 
interface
interfaceinterface
interface
 
Testing &ampdebugging
Testing &ampdebuggingTesting &ampdebugging
Testing &ampdebugging
 
concurrency control
concurrency controlconcurrency control
concurrency control
 
Education
EducationEducation
Education
 
Formal verification
Formal verificationFormal verification
Formal verification
 
Transaction management
Transaction management Transaction management
Transaction management
 
Multi thread
Multi threadMulti thread
Multi thread
 
System testing
System testingSystem testing
System testing
 
software maintenance
software maintenancesoftware maintenance
software maintenance
 
e governance
e governancee governance
e governance
 
recovery management
recovery managementrecovery management
recovery management
 
Implementing polymorphism
Implementing polymorphismImplementing polymorphism
Implementing polymorphism
 
Buffer managements
Buffer managementsBuffer managements
Buffer managements
 
os linux
os linuxos linux
os linux
 
Ipv4
Ipv4Ipv4
Ipv4
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

exception handling

  • 1. EXCEPTION HANDLING Submitted by D.Shanmugapriya II-Msc(IT) Department of CS & IT Nadar Saraswathi college of Arts & Science Theni.
  • 2. Contents • Errors and Exception • Exception Handling Mechanism • Try,catch and throw • Re-throwing an exception • Specifying Exceptions
  • 3. What is an Error? • An Error is a term used to describe any issue that arises unexpectedly and results in incorrect output What are the Different types of errors? Logical error: • Occur due to poor understanding of problem or solution procedure. Syntatic error: • Arise due to poor understanding of the language itself. What is an exception? • Exception are runtime anomalies or unusual conditions that a program may encounter while executing.
  • 4. Exception Handling • Exceptions are of two types: • Synchronous exceptions • The exceptions which occur during the program execution due to some fault in the input data are known as synchronous exceptions. • For example:errors such as out of range, overflow,underflow. • Asynchronous exceptions • The exceptions caused by events or faults unrelated to the program and beyond the control of the program are called asynchronous exceptions. • Example:errors such as keyboard interrupts hardware malfunctions,disk failure.
  • 5. Exception Handling Mechanism • Exception handling Mechanism provides a means to detect and report an exception circumstances. • Find the problem (hit the exception) • Inform that an Error has occurred (throw the exception) • Receive the error information (catch the exception) • Take corrective Actions(handle the exception)
  • 6. Types of Exception Handling • The exception handling mechanism is bulit upon three keywords: • TRY • Is used to perface a block of statements which may generate exception. • THROW • When an exception is detected,it is thrown using a throw statement in the try block. • CATCH • A catch block defined by the keyword catch catches the exception thrown by the throw statement in the try block and handles it appropriately.
  • 7. Exception thrown by functions • Int main() • { • Try • { • Divide(10,20,30); • Divide (10,10,20); • } • Catch(int I) • { • Cout <<“n exception caught”; • } • Return 0; 1.Throw point Function that causes an exception 2.Try block Invokes a function that contains an exception 3.Catch block Catches and handles the exception
  • 8. Throwing mechanism • When an exception is desired to be handled is detected,it is thrown using the throw statement. • Throw statement has one of the following forms: • Throw (exception) • Throw exception • Throw; • The operand object exception may be of any type, including constants.
  • 9. Multiple catch statements • Multiple catch statements can be associated with a try block. • When an exception is thrown,the exception handlers are searched for an appropriate match. • The first handler that yields the match is executed. • After executed the handler,the controls goes to the first statement after the last catch block for that try.
  • 10. Multiple catch statements Int main() { Cout<<“n x ==1”; Test(1); Cout<<“n x==0”; Test(0); Cout<<“n x==-1”; Test(-1); Cout<<“n x==2”; Test(2); Return 0; }
  • 11. Catching mechanism • The type indicates the type of exception that catch block handles. • The catch statement catches an exception whose type matches with the type of catch argument. A catch block like a function definition Catch(type arg) { //Statements for managing exceptions. }
  • 12. Catch all Exception • A catch statement can also force to catch all Exception instead of a certain type alone. • Int main() • { • Cout<<“n testing generic catch”; • Test(1); • Test(0); • Test(-1); • Test(2); • Return 0; • }
  • 13. Re-throwing exception • A handler can rethrow the exception caught without processing it. • This can be done using throw without any argument. • Here the current exception is thrown to the next enclosing try/catch block. • Every time when an exception is re-thrown it will not be caught by the same catch statements rather it will be caught by the catch statement outside the try catch block.