SlideShare a Scribd company logo
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 handling
Harry Potter
 
What is Exception Handling?
What is Exception Handling?What is Exception Handling?
What is Exception Handling?
Syed Bahadur Shah
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
priyankazope
 
Java
JavaJava
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
parag
 
Exception handling in JAVA
Exception handling in JAVAException handling in JAVA
Exception handling in JAVA
Kunal Singh
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
raksharao
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Adil Mehmoood
 
Exception Handling
Exception HandlingException Handling
Exception Handling
backdoor
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
Nuha Noor
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
Nahian Ahmed
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
JasmeetSingh326
 

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

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
estorebackupr
 
Exception handling
Exception handlingException handling
Exception handling
Pranali Chaudhari
 
Unit 5
Unit 5Unit 5
Exception handling in java.pptx
Exception handling in java.pptxException handling in java.pptx
Exception handling in java.pptx
ARUNPRANESHS
 
java.pptx
java.pptxjava.pptx
java.pptx
sujatha629799
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
lalithambiga kamaraj
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handling
raksharao
 
Unit iii pds
Unit iii pdsUnit iii pds
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
teach4uin
 
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
promila09
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
AboMohammad10
 
Pi j4.2 software-reliability
Pi j4.2 software-reliabilityPi j4.2 software-reliability
Pi j4.2 software-reliability
mcollison
 
Exception
ExceptionException
Exception
Harry Potter
 
Exception
ExceptionException
Exception
Tony Nguyen
 
Exception
ExceptionException
Exception
Luis Goldster
 
Exception
ExceptionException
Exception
Young Alista
 
Exception
ExceptionException
Exception
Hoang Nguyen
 
Exception
ExceptionException
Exception
James Wong
 
Exception
ExceptionException
Exception
Fraboni Ec
 

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
 
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
 
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 techniques
Siva Priya
 
Class properties
Class propertiesClass properties
Class properties
Siva Priya
 
Planning the development process
Planning the development processPlanning the development process
Planning the development process
Siva Priya
 
recovery management with concurrent controls
recovery management with concurrent controlsrecovery management with concurrent controls
recovery management with concurrent controls
Siva Priya
 
Retail of big data analytics
Retail of big data analyticsRetail of big data analytics
Retail of big data analytics
Siva Priya
 
Deadlock and shadow paging
Deadlock and shadow pagingDeadlock and shadow paging
Deadlock and shadow paging
Siva Priya
 
Mobile IP
Mobile IPMobile IP
Mobile IP
Siva Priya
 
density based method and expectation maximization
density based method and expectation maximizationdensity based method and expectation maximization
density based method and expectation maximization
Siva Priya
 
Classification by backpropacation
Classification by backpropacationClassification by backpropacation
Classification by backpropacation
Siva Priya
 
Disk scheduling & Disk management
Disk scheduling & Disk managementDisk scheduling & Disk management
Disk scheduling & Disk management
Siva Priya
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
Siva Priya
 
Servlets & jdbc
Servlets & jdbcServlets & jdbc
Servlets & jdbc
Siva 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

Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 

Recently uploaded (20)

Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 

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.