catch/rethrow

James Pelcis jpelcis at gmail.com
Wed Jun 7 09:55:50 PDT 2006


The reason Object works is because the definition of Exception is

class Exception : Object
{
// blah
}

You can use

catch (Exception o) {
	throw o;
}

or

catch (Object o) {
	throw o;
}

or just not catch it at all.

Sean Kelly wrote:
> 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