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

Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling pptJavabynataraJ
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling ConceptsVicter Paul
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#Abid Kohistani
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Janki Shah
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVASURIT DATTA
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaARAFAT ISLAM
 
Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 
Call by value
Call by valueCall by value
Call by valueDharani G
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 

What's hot (20)

Method overriding
Method overridingMethod overriding
Method overriding
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
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
 
Exceptions handling notes in JAVA
Exceptions handling notes in JAVAExceptions handling notes in JAVA
Exceptions handling notes in JAVA
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Call by value
Call by valueCall by value
Call by value
 
Exception handling
Exception handlingException handling
Exception handling
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Java awt
Java awtJava awt
Java awt
 
Exception handling
Exception handling Exception handling
Exception handling
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Exception handling in .net
Exception handling in .netException handling in .net
Exception handling in .net
 

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
 
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
 
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

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Recently uploaded (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

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.