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

Assignment Help:

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.


Related Discussions:- What does throw; (with no exception object after the throw

C CODING, HOW THE C PROGRAM CODING IMPLEMENTED DY ITSELF UNDERSTANDING . AL...

HOW THE C PROGRAM CODING IMPLEMENTED DY ITSELF UNDERSTANDING . ALSO HOW I CAN A BECOME A GOOD PROGRAMMER IN C WHAT I DO FOR GOOD PROGRAMMING ,TELL ME HOW C CODING DEVELOP DY ITSELF

Doubt!, find the greater of the two variables, without using conditional lo...

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

Define the return statement in computer programming, Define The Return Stat...

Define The Return Statement in Computer Programming? The return statement is used for two purposes once the return statement is executed the program control will be immediately

Assignment, Develop a C++ program that uses a while to determine the gross ...

Develop a C++ program that uses a while to determine the gross pay (in Dollars) for each of several employees. The company pays “straight-time” for the first 40 hours worked by ea

Sort wars, Explain each of the algorithms in a way that would be understand...

Explain each of the algorithms in a way that would be understandable to an intelligent person who is not familiar with programming. You should not use any code (or even pseudo code

Blanche has a fashion design company called BLB_Best_Clothin, Blanche has a...

Blanche has a fashion design company called BLB_Best_Clothing Pty. That she has just opened recently

Program for number game, - Create a program that uses at least two function...

- Create a program that uses at least two functions that will be called from your main. This program is a number game program that asks for parts of your phone and after manipulati

Tower of hanoi, application problem of tower of hanoi

application problem of tower of hanoi

E^x, Write a program to calculate e^x using the formula: e^x = 1 + x/1! + ...

Write a program to calculate e^x using the formula: e^x = 1 + x/1! + x^2/2! + x^3/3! + ...... Allow the user to enter the integer number x, then do the calculation in a loop (for

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd