[phobos] Exception chaining

Andrei Alexandrescu andrei at erdani.com
Tue Jan 11 16:01:15 PST 2011


A nothrow function must either call only nothrow functions or 
catch(Exception) for all others. Anything else shouldn't compile.

Andrei

On 1/11/11 2:36 PM, Sean Kelly wrote:
> On Jan 11, 2011, at 1:57 AM, Don Clugston wrote:
>>
>> So the general scheme appears to work.
>> But, there's something I'm unclear about. When should chained
>> exceptions be catchable?
>> They are very nasty creatures, and you really want to know when they happen.
>> Presumably, an AssertError which occurs while processing an
>> FileException, should not be silently chained
>> and caught in the FileException.
>> In fact, should a chain containing an Error be catchable at all?
>
> Tricky question.  According to TDPL, this is all collateral damage, so I'd expect the chain to be caught just fine.  Worse is something like this:
>
> void fnA() nothrow {
>      try {
>          fnB(); // documented to throw OopsException
>      } catch (OopsException e) {}
> }
>
> void fnB() {
>      scope(exit) closeFile();
>      throw new OopsException;
> }
>
> void closeFile() {
>      throw new UnableToCloseFileException;
> }
>
> Is this code correct or does it violate the nothrow guarantee?
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list