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

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Sun Oct 5 09:27:41 PDT 2014


On Sunday, 5 October 2014 at 16:18:33 UTC, Andrei Alexandrescu 
wrote:
> On 10/5/14, 8:56 AM, Jacob Carlborg wrote:
>> I would like to have as specific exception type as possible. 
>> Also a nice
>> hierarchy of exception when catching a specific exception is 
>> not
>> interesting. Instead of just a FileException there could be
>> FileNotFoundException, PermissionDeniedExcepton and so on.
>
> Exceptions are all about centralized error handling. How, and 
> how often, would you handle FileNotFoundException differently 
> than PermissionDeniedException?
>
> Andrei

While precise formalization of the principle is hard I think this 
comment nails it in general. When defining exceptions hierarchies 
it makes sense to think about it in terms of "what code is likely 
to catch it and why?" and not "what this code should throw?". 
Dedicated exception type only makes sense if it is a common to 
catch it separately, any additional details can be stored as 
runtime field (like status code for HTTPStatusException)


More information about the Digitalmars-d mailing list