On Tue, Jul 03, 2001 at 03:10:05PM +0200, Shachar Shemesh wrote:
> short C++ code:
>
> void A()
> {
>     try
>     {
>         class someclass var1(constructor_arguments);
> 
>         B();
>         some_more_activities();
>     } catch( ... )
>     {
>         some_exception_code();
>     }
> }
> 
> void B()
> {
>     class someotherclass var2( constructor_arguments );
> 
>     ...
>     C();
> }
> 
> 
> void C()
> {
>     blah();
> 
>     if( adi_stav_was_here==true )
>         throw NOOOOOOO(5);
> }
> 
> If we try to (as CFront used to do) compile this code into C, we see 
> that the long jump triggered by the throw in function C must stop inside 
> function B, in order to run the var2 destructor. This catch handler can 
> then long jump to function A to handle the explicit catch handler.

I've never used CFront. But why would an implicit exception handler
be different from an explicit one? That could easily be implemented
by having each exception handler keep a pointer to the previous jmp_buf, 
restore it once it finishes (either naturally or through exception).

> Conclusion 1 - if you enable exception handling in C++, all your 
> functions probably carry exception handlers (there are good things to 
> say for Java's "you must declare exceptions" syntax).

If it makes you happy, I've always considered those kind of safe 
destructors the most useful thing in C++, and the lack of useable
exceptions the most annoying feature-lack of C.

> Conclusion 2 - exceptions are not global, far from it.

You always have only one active exception handler at a time. That's
what I mean by "global". Can you imagine a situation where you'd want to 
pass one of two jmp_buf pointers, say, based on the value of a flag?

> For those of you still only programming in C, replace "destructor" with 
> "cleanup code".

Actually I find that a lot of people nowdays start with C++ or Java and 
move to C later. Like I did, even though I switched very early 
experience-wise.

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to