can someone please try and explain something to me...

i have 2 functions, lets call them FuncA and FuncB. FuncA calls FuncB, and FuncB does some stuff then simply returns. both functinos are placed in try...catch statements:

void FuncA()
{
    try
    {
        FuncB();
    }
    catch
    {
         trace("FuncA caught exception calling FuncB");
    }
}
void FuncB()
{
    //other code
    .
    .
    .
    try
    {
        DoSomethingElse();
    }
    catch
    {
         trace("FuncB caught exception calling DoSomethingElse");
    }
    .
    .
    .
    .
    //other code
}

what i am seeing is that an exception is being thrown when DoSomethingElse is being called. BUT! what is being traced out is "FuncA caught exception calling FuncB". this to me is maddness because the function DoSomethingElse is wrapped around its own try---catch handler, so i would expect "FuncB caught exception calling DoSomethingElse" to be traced out.

can anyone give an explanation as to why this might happen?

extra info:
FuncA, FuncB, and DoSomethingElse are not the real function names in my app (unsuprisingly). In reality FuncA is a normal function in an exe, and FuncB is a function on a COM interface (so FuncA actually calls CoCreateInstance before calling FuncB on the COM object). And inside FuncB, DoSomethingElse is actually an ADO function that i am calling on one of microsoft's ADO COM components. i do not think these details are relevent to my question, hence i simplfied things.

thanks to anyone who replies.

Your catch statement in FuncB() is not setup to catch the specific exception that gets thrown from DoSomethingElse(), but the catch statement in FuncA() is.

right im sorry i made a mistake in my code snippit above.

the catch in both instances is catch(...) which should catch EVERYTHING.

any more ideas ?

Sounds actually strange then, could it be your compiler that is misbehaving ...
Try compiling e.g. producing assembly with source and lookup what actually gets compiled.

> In reality FuncA is a normal function in an exe, and FuncB is a function on a COM interface
> (so FuncA actually calls CoCreateInstance before calling FuncB on the COM object).
> And inside FuncB, DoSomethingElse is actually an ADO function that i am calling
> on one of microsoft's ADO COM components.
> i do not think these details are relevent to my question ...
these details are *very* relevant to your question. the innermost scope of execution of a com object is an apartment. unless the thread in your exe and the com objects involved are in the same apartment (either the MTA or the same STA), remoting is involved. what looks like an object to you (what was returned by CoCreateInstance) would really be a proxy; the method call would be forwarded to another thread which is in the same apartment as the object on which the method is invoked. c++ exceptions cannot be thrown or caught across thread boundaries (there is a separate stack for each thread). to marshal exceptions across apartment boundaries, use the COM exception mechanism (IErrorInfo).

This article has been dead for over six months. Start a new discussion instead.