G
Grizlyk
Hello
I want to understand the exception habdling in C++ more, because i
think no one can apply anything free (free - without remembering large
unclear list of rules and exceptions from rules and exceptions from
exception from rules) if he does not understand "why" the thing have
done excactly as is.
I know, some people do not agree with me at the point of "why".
1.
I think, the exception is statical linknig, in other words, each throw
"knows" it appropriate catch during comile time.
Is it true?
I think it is true, due to exit() called, if no external try{} block
exist (no "stack unwinding" has occured).
What exactly happends while exceptions? In asm list i can see something
like this:
call function
normal return point:
clear stack if needed
uncondition jmp to exit
return from exception point:
clear stack if needed
push retruned value
call ___cxa_begin_catch
exit:
2.
The question is next:
I have destructor, which can be executed after exception have thrown,
during "stack unwinding". My destructor can create temporary objects,
and each of the created object can throw, in general.
If i throw while i have std::uncaught_exception()!=0, the exit() (oh,
mamma mia will be called.
But if i declare new try{} block inside destructor, can temporary
objects safe throw or can not and why?
~Base()
{
try{
A a;
B b;
Base::free(a,b);
}catch(...){ if( !std::uncaught_exception() ) throw; }
}
Why?
Thanks.
I want to understand the exception habdling in C++ more, because i
think no one can apply anything free (free - without remembering large
unclear list of rules and exceptions from rules and exceptions from
exception from rules) if he does not understand "why" the thing have
done excactly as is.
I know, some people do not agree with me at the point of "why".
1.
I think, the exception is statical linknig, in other words, each throw
"knows" it appropriate catch during comile time.
Is it true?
I think it is true, due to exit() called, if no external try{} block
exist (no "stack unwinding" has occured).
What exactly happends while exceptions? In asm list i can see something
like this:
call function
normal return point:
clear stack if needed
uncondition jmp to exit
return from exception point:
clear stack if needed
push retruned value
call ___cxa_begin_catch
exit:
2.
The question is next:
I have destructor, which can be executed after exception have thrown,
during "stack unwinding". My destructor can create temporary objects,
and each of the created object can throw, in general.
If i throw while i have std::uncaught_exception()!=0, the exit() (oh,
mamma mia will be called.
But if i declare new try{} block inside destructor, can temporary
objects safe throw or can not and why?
~Base()
{
try{
A a;
B b;
Base::free(a,b);
}catch(...){ if( !std::uncaught_exception() ) throw; }
}
Why?
Thanks.