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

Exception handling
Exception handlingException handling
Exception handlingHarry Potter
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javapriyankazope
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Javaparag
 
Exception handling in JAVA
Exception handling in JAVAException handling in JAVA
Exception handling in JAVAKunal Singh
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handlingraksharao
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaAdil Mehmoood
 
Exception Handling
Exception HandlingException Handling
Exception Handlingbackdoor
 
Exceptionhandling
ExceptionhandlingExceptionhandling
ExceptionhandlingNuha Noor
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 

What's hot (12)

Exception handling
Exception handlingException handling
Exception handling
 
What is Exception Handling?
What is Exception Handling?What is Exception Handling?
What is Exception Handling?
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Java
JavaJava
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
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
 

Similar to Web technology (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
Exception handlingException handling
Exception handling
 
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
 
java.pptx
java.pptxjava.pptx
java.pptx
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handling
 
Unit iii pds
Unit iii pdsUnit iii pds
Unit iii pds
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
 
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
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 
Exception
ExceptionException
Exception
 

More from Siva Priya

source code metrics and other maintenance tools and techniques
source code metrics and other maintenance tools and techniquessource code metrics and other maintenance tools and techniques
source code metrics and other maintenance tools and techniquesSiva Priya
 
Class properties
Class propertiesClass properties
Class propertiesSiva Priya
 
Planning the development process
Planning the development processPlanning the development process
Planning the development processSiva Priya
 
recovery management with concurrent controls
recovery management with concurrent controlsrecovery management with concurrent controls
recovery management with concurrent controlsSiva Priya
 
Retail of big data analytics
Retail of big data analyticsRetail of big data analytics
Retail of big data analyticsSiva Priya
 
Deadlock and shadow paging
Deadlock and shadow pagingDeadlock and shadow paging
Deadlock and shadow pagingSiva Priya
 
density based method and expectation maximization
density based method and expectation maximizationdensity based method and expectation maximization
density based method and expectation maximizationSiva Priya
 
Classification by backpropacation
Classification by backpropacationClassification by backpropacation
Classification by backpropacationSiva Priya
 
Disk scheduling & Disk management
Disk scheduling & Disk managementDisk scheduling & Disk management
Disk scheduling & Disk managementSiva Priya
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithmSiva Priya
 
Servlets & jdbc
Servlets & jdbcServlets & jdbc
Servlets & jdbcSiva Priya
 

More from Siva Priya (12)

source code metrics and other maintenance tools and techniques
source code metrics and other maintenance tools and techniquessource code metrics and other maintenance tools and techniques
source code metrics and other maintenance tools and techniques
 
Class properties
Class propertiesClass properties
Class properties
 
Planning the development process
Planning the development processPlanning the development process
Planning the development process
 
recovery management with concurrent controls
recovery management with concurrent controlsrecovery management with concurrent controls
recovery management with concurrent controls
 
Retail of big data analytics
Retail of big data analyticsRetail of big data analytics
Retail of big data analytics
 
Deadlock and shadow paging
Deadlock and shadow pagingDeadlock and shadow paging
Deadlock and shadow paging
 
Mobile IP
Mobile IPMobile IP
Mobile IP
 
density based method and expectation maximization
density based method and expectation maximizationdensity based method and expectation maximization
density based method and expectation maximization
 
Classification by backpropacation
Classification by backpropacationClassification by backpropacation
Classification by backpropacation
 
Disk scheduling & Disk management
Disk scheduling & Disk managementDisk scheduling & Disk management
Disk scheduling & Disk management
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
 
Servlets & jdbc
Servlets & jdbcServlets & jdbc
Servlets & jdbc
 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
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
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
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
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
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
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Recently uploaded (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
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...
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
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?
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
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
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Web technology

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