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
A palindrome is a string that reads the same from the both the ends. Given a string S convert it to a palindrome by doing character replacement. Your takes is to convert S to palin

Illustration of Grid function: For illustration, the script below creates two individual figure windows. At First, it clears the figure window. Then, it generates an x vector

pls say code for this above..

A: Provided that function parameter is "const reference", compiler create temporary variable in following two ways. a) The actual argument is the correct type, however it isn't

Environment - C, Linux Duration - December 2006 to Feb 2007 Description - TR-106 specifies a generic data model template applicable for all TR-069 enabled devices. Adde

a program that declares and prompts the user to enter two integer and performs the five arithmetic operations

#question.to determine the area of a triangle,rectangle and trapezium

how to program?

Verifone pos offline mod vx670 Project Description: I want a programmer who will build custom application for Offline VX670 to collect and save info+pin 1) Press the am

find the greater of the two variables, without using conditional loops or ternary operators?