catch/rethrow

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


kris wrote:
> Sean Kelly wrote:
>> Johan Granberg wrote:
>>
>>> Sean Kelly wrote:
>>>
>>>> But it relies on undocumented (I believe) knowledge that all 
>>>> exceptions in D are objects ...
>>>> Sean
>>>
>>>
>>> quote from the specification (statements throw)
>>> "Expression is evaluated and must be an Object reference. The Object 
>>> reference is thrown as an exception."
>>>
>>> So it is documented that Exceptions is objects.
>>
>>
>> Ah, good to know.  But then what is the purpose of catch{}?  Without 
>> the ability to rethrow, it seems to have marginal utility.
> 
> Sean; I thought you could rethrow:
> 
> catch (Exception e)
>        throw e;

You can for the above case.  But D also supports:

     catch{ ... }

ie. without the "(Exception e)".  However, unlike C++, "throw;" in this 
instance is invalid so there's no way to rethrow the exception.

Basically, I'm wondering why this form of catch exists.  It can catch 
exceptions but not report anything about them (as it has no object 
reference), and it can't rethrow them.  I can't think of a single case 
where I would actually use this statement as it exists now.


Sean



More information about the Digitalmars-d mailing list