Program logic bugs vs input/environmental errors (checked exceptions)

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 1 16:19:32 PDT 2014


On 10/1/14, 4:00 PM, Sean Kelly wrote:
> On Wednesday, 1 October 2014 at 22:42:27 UTC, Jeremy Powers via
> Digitalmars-d wrote:
>>
>> If you see "throws Exception" in java code chances are the code is
>> broken,
>> same as if you see "catch (Exception" - this tells you nothing about the
>> exception that happened, and hence you can do nothing with it. So you
>> either swallow (and silently break in many cases) or rethrow (and
>> break for things you needn't have).  As mentioned, the standard way to
>> avoid this is to have a parent exception type appropriate to the
>> abstraction in the API, and throw subtypes in the implementation.
>> Among other things, this means you can change the implementation to
>> throw different exceptions without breaking any users (who will
>> already be catching the parent exception).
>
> ....while in Phobos, most of the subtyped exceptions were
> eliminated a while back in favor of just always throwing
> Exception.

My recollection is that was only talked about. Anyhow, one thing is 
clear - as of now there are no clear idioms and successful techniques 
for handling errors with exceptions (including the use of subtyping). -- 
Andrei



More information about the Digitalmars-d mailing list