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
Explain the Bit Wise Operators? C language has distinction of supporting special operators recognized as bit wise operators for manipulation of data at bit level. These operato

C program to count the words: void CountWords();          void main()          {             printf("\n\tcount the words and enter string\n\n\n");             Count

Create a program that asks the user for two integers which represent the numerator and denominator parts of fraction. Print out a simplification of the fraction. Example: Enter th


superposition of waves

What is inheritance? Class, the vehicle, which is used to execute object-oriented concepts in C++, has given a new dimension to this idea of reusability. Many vendors now offer

Problem 1 What is the difference between function declaration and function definition? 2 Write a recursive function to find sum of even numbers from 2 to 10. 3 List some

If quicksort is so quick, why bother with anything else? If bubble sort is so bad, why even mention it? For that matter, why are there so many sorting algorithms? Your mission (sho

in a multilist organisation

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome