catch/rethrow
Sean Kelly
sean at f4.ca
Wed Jun 7 14:06:16 PDT 2006
But then why have catch{} at all? It's actually less useful than
catch(Object) as it provides no facility to rethrow the exception, and
it offers nothing over catch(Object) in what it can catch. Also, it's
possible that a LastCatch block may simply be intended to detect a
failure condition and perform some operation (similar to stack(failure))
or that it may need to rethrow the exception if some global condition
cannot be met. Sure, you could use catch(Object) in these instances,
but then again, what is the purpose of catch{}? Surely it can't simply
be to avoid typing "(Object o)"?
James Pelcis wrote:
> The purpose is to inform the user that there has been an error without
> overly interrupting the program. I think the rationale is that after
> you have taken the time to handle an exception, why would you rethrow it?
>
> If you disagree, you don't need to have the kind of catch. You can
> always catch either Exception or Object and ignore the LastCatch.
>
> 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
More information about the Digitalmars-d
mailing list