catch/rethrow

Sean Kelly sean at f4.ca
Wed Jun 7 09:14:06 PDT 2006


In C++ if I want to catch and rethrow any exception I can do this:

   try {

   } catch(...) {
     throw;
   }

The roughly equivalent syntax in D would be this:

   try {

   } catch {
     throw;
   }

But currently, 'throw' must be followed by an expression in D.  This works:

   try {

   } catch(Object o) {
     throw o;
   }

But it relies on undocumented (I believe) knowledge that all exceptions 
in D are objects and also subverts the need for a LastCatch statement. 
Is there any D equivalent of the C++ code above, barring the use of 
scope(failure)?  And why is there no way to rethrow the exception caught 
by a LastCatch statement?


Sean



More information about the Digitalmars-d mailing list