SlideShare a Scribd company logo
4
Most read
5
Most read
8
Most read
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

PPTX
Exception Handling in object oriented programming using C++
PPTX
class and objects
PPTX
Exception handling c++
PPTX
Presentation on-exception-handling
PPTX
Basic Data Types in C++
PPTX
Constructor and Types of Constructors
PPTX
Java exception handling
PDF
Exception handling
Exception Handling in object oriented programming using C++
class and objects
Exception handling c++
Presentation on-exception-handling
Basic Data Types in C++
Constructor and Types of Constructors
Java exception handling
Exception handling

What's hot (20)

PPTX
Java program structure
PDF
Python programming : Control statements
PPTX
classes and objects in C++
PPTX
Pointers in c++
PPTX
Dynamic memory allocation in c
PPTX
Variables in C++, data types in c++
PPTX
Programming in c Arrays
PDF
Python exception handling
PPTX
PPTX
Pointers in c++
PPT
Function overloading(c++)
PPT
Files in c++ ppt
PPTX
Exception Handling in C++
PPT
Method overriding
PPTX
Java Data Types
PDF
Java thread life cycle
PPTX
Pointers in C
PPTX
Function overloading and overriding
PPTX
Type conversion
Java program structure
Python programming : Control statements
classes and objects in C++
Pointers in c++
Dynamic memory allocation in c
Variables in C++, data types in c++
Programming in c Arrays
Python exception handling
Pointers in c++
Function overloading(c++)
Files in c++ ppt
Exception Handling in C++
Method overriding
Java Data Types
Java thread life cycle
Pointers in C
Function overloading and overriding
Type conversion
Ad

Similar to exception handling (20)

PPTX
Exceptions in C++ Object Oriented Programming.pptx
PPTX
Exception handling in java
PPTX
Exception handling in java.pptx
PPTX
Exceptionhandling
PPTX
java.pptx
PPTX
Exception Handling in Java
PDF
16 exception handling - i
PPTX
Java-Unit 3- Chap2 exception handling
PPTX
Chap2 exception handling
PPTX
Java class 7
PDF
22 scheme OOPs with C++ BCS306B_module5.pdf
PPTX
L14 exception handling
PPT
A36519192_21789_4_2018_Exception Handling.ppt
PPT
Exception Handling Exception Handling Exception Handling
PDF
Lesson 8 Handling Exceptions and Errors.pdf
PPTX
Pi j4.2 software-reliability
PPT
Exception
Exceptions in C++ Object Oriented Programming.pptx
Exception handling in java
Exception handling in java.pptx
Exceptionhandling
java.pptx
Exception Handling in Java
16 exception handling - i
Java-Unit 3- Chap2 exception handling
Chap2 exception handling
Java class 7
22 scheme OOPs with C++ BCS306B_module5.pdf
L14 exception handling
A36519192_21789_4_2018_Exception Handling.ppt
Exception Handling Exception Handling Exception Handling
Lesson 8 Handling Exceptions and Errors.pdf
Pi j4.2 software-reliability
Exception
Ad

More from rajshreemuthiah (20)

PPTX
PPTX
PPTX
PPTX
polymorphism
PPTX
solutions and understanding text analytics
PPTX
interface
PPTX
Testing &ampdebugging
PPTX
concurrency control
PPTX
Education
PPTX
Formal verification
PPTX
Transaction management
PPTX
Multi thread
PPTX
System testing
PPTX
software maintenance
PPTX
e governance
PPTX
recovery management
PPTX
Implementing polymorphism
PPSX
Buffer managements
PPTX
os linux
PPTX
polymorphism
solutions and understanding text analytics
interface
Testing &ampdebugging
concurrency control
Education
Formal verification
Transaction management
Multi thread
System testing
software maintenance
e governance
recovery management
Implementing polymorphism
Buffer managements
os linux

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
Spectral efficient network and resource selection model in 5G networks
Univ-Connecticut-ChatGPT-Presentaion.pdf
Getting Started with Data Integration: FME Form 101
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
SOPHOS-XG Firewall Administrator PPT.pptx
Encapsulation_ Review paper, used for researhc scholars
Machine Learning_overview_presentation.pptx
Tartificialntelligence_presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
MIND Revenue Release Quarter 2 2025 Press Release
Mobile App Security Testing_ A Comprehensive Guide.pdf
Network Security Unit 5.pdf for BCA BBA.
cloud_computing_Infrastucture_as_cloud_p
TLE Review Electricity (Electricity).pptx
Unlocking AI with Model Context Protocol (MCP)

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.