unexpected exception handler

G

George2

Hello everyone,


This question is about when it is allowed to call throw to re-throw
exception -- make the exception re-throw.

I can only think of two situations,

1. in catch block of an exception;
2. in unexpected handler.

For (2), in unexpected handler, since the input parameter is null, so
in order to get the exception information, we need to re-throw it and
catch it to get exception informaiton.

Is my understanding correct? Here is some pseudo code from Bjarne's
book.

Code:
// suppose throwY is unexpcted handler
void throwY() throw (Yunexpected)
{
    try{
        throw; // have to re-throw and catch in order to get exception
information since current input parameter is null and has no exception
information, my understanding correct?
    } catch (Network_exception& p)
    {
        throw (Yunexpected (&p));
    } catch (...)
    {
        throw (Yunexpected (0));
    }
}


thanks in advance,
George
 
S

suresh shenoy

Hello everyone,

This question is about when it is allowed to call throw to re-throw
exception -- make the exception re-throw.

I can only think of two situations,

1. in catch block of an exception;
2. in unexpected handler.

For (2), in unexpected handler, since the input parameter is null, so
in order to get the exception information, we need to re-throw it and
catch it to get exception informaiton.

Is my understanding correct? Here is some pseudo code from Bjarne's
book.

Code:
// suppose throwY is unexpcted handler
void throwY() throw (Yunexpected)
{
    try{
        throw; // have to re-throw and catch in order to get exception
information since current input parameter is null and has no exception
information, my understanding correct?
    } catch (Network_exception& p)
    {
        throw (Yunexpected (&p));
    } catch (...)
    {
        throw (Yunexpected (0));
    }}

thanks in advance,
George

George,

In a design perspective when you have multiple levels of function
calls, you would most likely write a class (holding exception
information) and create an object of this in the nth level and pass it
all the way up and process it at a central location.
As an example,

class myexception {

....
}

void Func_One() {
try
{
Func_Two();
}
catch(some exception)
{
do this;
}
...
catch(myexception)
{
throw;
}
}

void Func_Two() {
try
{
Func_Three();
}
catch(some exception)
{

}
catch(myexception)
{
throw;
}
}

void Func_Three() {
try
{
something;
}

catch(...)
{
throw new myexception();
}

}

When you encounter a throw the control is passed backed to the calling
function with app info unless there is finally block.

Suresh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top