0% found this document useful (0 votes)
14 views2 pages

Exception Handling

Hand

Uploaded by

RCM For all
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Exception Handling

Hand

Uploaded by

RCM For all
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exception Handling

exceptions are runtime anomalies or abnormal conditions that a program encounters


during its execution. The process of handling these exceptions is called exception
handling. Using the exception handling mechanism, the control from one part of the
program where the exception occurred can be transferred to another part of the code.

An exception is an unexpected problem that arises during the execution of a program


our program terminates suddenly with some errors/issues. Exception occurs during
the running of the program (runtime).

Types of C++ Exception


1. try in C++
The try keyword represents a block of code that may throw an exception
placed inside the try block. It’s followed by one or more catch blocks. If an
exception occurs, try block throws that exception.
General Syntax:

try {

// code that may raise an exception


throw argument;
}

2. catch in C++
The catch statement represents a block of code that is executed when a
particular exception is thrown from the try block. The code to handle the
exception is written inside the catch block.
General Syntax:

catch (exception) {
// code to handle exception
}
3. throw in C++
An exception in C++ can be thrown using the throw keyword. When a
program encounters a throw statement, then it immediately terminates the
current function and starts finding a matching catch block to handle the
thrown exception.
General Syntax:

try {

// code that may raise an exception


throw argument;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy