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
There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

Introduction. In this assignment you are required to revisit the Assignment 1 topic. You will develop a new program which is more sophisticated, in particular, adding more functio

Linear search in array - C program: Write a program in c to define a linear search in array. void main()                 {                 clrscr();

In this worksheet you are asked to write three classes in C++: Lecture class, Course class and University class. The classes relate to each other in the way that a Course has many

write c program to do the following : -fill 2 dimensional array (square matrix array with size=4). -ask the user to enter any integer number and add this number to the diagonals -o

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

write a c++ program, that finds the minimum total number of shelves, including the initial one, required for this loading process.

Project Description: Prepare software that will work with our USB hardware that easily lets you backup all the pictures in your computer into the USB stick in one single step. Once

minimum total number of shelves.

write a program to find the area under the curve y=f(x) between x=a and x=b integrate y=f(x)   #include float start_point, /* GLOBAL VARIABLES */