Topic: Throwing from destructors, again.


Author: Ben Pfaff <pfaffben@msu.edu>
Date: Mon, 30 Oct 2000 22:19:39 GMT
Raw View
Anatoli Tubman <anatoli@my-deja.com> writes:

>  What about changing the language in such a way that multiple
> exceptions are allowed to coexist? Throwing from destructors would
> mean "add new exception to the currently running exception set and
> continue unwinding" which is safe.  My proposal is very informal at
> this stage.

Explain how this is relevant to comp.lang.c?  C doesn't have
exceptions or destructors.

Followups set.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: remove.haberg@matematik.su.se (Hans Aberg)
Date: Mon, 30 Oct 2000 22:53:04 GMT
Raw View
In article <87aebm16n0.fsf@pfaffben.user.msu.edu>, pfaffben@msu.edu wrote:
>>  What about changing the language in such a way that multiple
>> exceptions are allowed to coexist? Throwing from destructors would
>> mean "add new exception to the currently running exception set and
>> continue unwinding" which is safe.  My proposal is very informal at
>> this stage.
>
>Explain how this is relevant to comp.lang.c?  C doesn't have
>exceptions or destructors.

I think that C object code that should be used together with C++ object
code that admits exceptions must be compiled so that it too is aware of
exceptions. :-)

  Hans Aberg      * Anti-spam: remove "remove." from email address.
                  * Email: Hans Aberg <remove.haberg@member.ams.org>
                  * Home Page: <http://www.matematik.su.se/~haberg/>
                  * AMS member listing: <http://www.ams.org/cml/>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Anatoli Tubman <anatoli@my-deja.com>
Date: Mon, 30 Oct 2000 18:43:14 GMT
Raw View
 What about changing the language in such a way that multiple
exceptions are allowed to coexist? Throwing from destructors would
mean "add new exception to the currently running exception set and
continue unwinding" which is safe.  My proposal is very informal at
this stage.

When an exception escapes a destructor as a result of stack
unwinding, we (instead of calling terminate ()) just add
the offending exception to the current exception set.
Semantics of try/catch becomes a bit more complicated.
As we have multiple active exceptions now, more than one
catch clause of a given block can be executed. Throw from
within a catch() does not take effect immediately but only
after all exceptions from the current list are handled.

Here's the algorithm of new try/catch:

         try { something(); }
           catch (A)   { }
           catch (B)   { }
           catch (...) { }

becomes:

         try { something(); }
         catch (...) {
           new_e_list = empty_list;
           for each e in old_e_list {
             try {
               try { throw e }
                 catch (A)   { } // old sequence
                 catch (B)   { } // of catch blocks
                 catch (...) { } // goes here, unchanged
             }
             catch (...) {
               insert caught exception in new_e_list
             }
           }
           if new_e_list is not empty
             resume unwinding with new_e_list
         }

The proposal is less radical than it seems, because meaning of old
programs is not changed. Well, old programs that terminate() because of
a double exception don't anymore, but even this can be cured: in case of
double exception, call the function double_exception(). The default
value of double_exception() is terminate(). Call to
       set_double_exception (handle_double_exceptions)
swithes to the described behaviour. Call to
       set_double_exception (terminate)
reverts to old behaviour.

Am I totally off here? Was such thing ever considered?


--
Regards
Anatoli (anatoli<at>ptc<dot>com) opinions aren't


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]