What does throw; (with no exception object after the throw , C/C++ Programming

What does throw; (with no exception object after the throw keyword) mean? Where would

I employ it?

A: You should see code that looks something like this:

class MyException {

public:

...

void addInfo(const std::string& info);

...

};

 

void f()

{

try {

...

}

catch (MyException& e) { e.addInfo("f() failed"); throw;

}

}

In this instance, the statement throws; refer to "re-throw the current exception." At this time, a function caught exception (through non-const reference), modified the exception (through adding up information to it), and re-threw the exception then. This idiom can be used to implement a simple form of stack- trace, adding suitable catch clauses in the important functions of your program.

Another re-throwing idiom is "exception dispatcher":

void handleException()

{

try {

throw;

}

catch (MyException& e) {

...code to handle MyException...

}

catch (YourException& e) {

...code to handle YourException...

}

}

void f()

{

try {

...something that might throw...

}

catch (...) {

handleException();

}

}

This idiom let a single function (handleException()) to be re-used to handle exceptions in number of other functions.

Posted Date: 3/19/2013 8:51:29 AM | Location : United States







Related Discussions:- What does throw; (with no exception object after the throw , Assignment Help, Ask Question on What does throw; (with no exception object after the throw , Get Answer, Expert's Help, What does throw; (with no exception object after the throw Discussions

Write discussion on What does throw; (with no exception object after the throw
Your posts are moderated
Related Questions
WHAT IS A C LANGUAGE? C IS A PROGRAMMING?

C o n t r o l S t r u c t u r e s I t i s o f t h r e e t y p e s: 1 .    S e qu e n c e s t r u c t u r e 2 .

Write a program that computes the cost of a long distance call. The cost of the call is determined according to the following rate schedules. a. A call made between 8:00 AM and

Convert a COV/CPE (Micosoft Fax Cover Page) file to a TIF image file Project Description: I would like a small API written that will take a COV/CPE file and replaced the corr

what is binary heap ? what is the c code for the implementation for the binary heap

Dereferencing the Pointer this Sometimes a member function requires to make a copy of the invoking instance so that it can change the copy without affecting the original instan

(RationalNumber Class) A rational number is a number that can be represented as the quotient of two integers. For example, 1/3, 5/7, 7/2, and so forth are rational numbers (By 2/1


The probabilistic Hough transform uses random sampling instead of an accumulator array. In this approach the number of random samples r, is not specified in the OpenCV call, but is

Design and implement a library system that does the following: ? Takes details of a student/library users: first name, last name, other names, user ID number, and nationality. Th