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

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Sun Oct 5 23:31:26 PDT 2014


On 05/10/14 18:18, Andrei Alexandrescu wrote:

> Exceptions are all about centralized error handling. How, and how often,
> would you handle FileNotFoundException differently than
> PermissionDeniedException?

Probably not that often. But I don't think it's up to "File" to decide 
that. I think "File" should throw a specific error as possible 
containing all details it has. Then it's up to the user of "File" how to 
handle the exception. If you're not interested in the differences 
between FileNotFoundException and PermissionDeniedException, then catch 
the base class instead.

The details provided between these two exception could be different as 
well. FileNotFoundException should contain the path of the file that 
wasn't found. PermissionDeniedException should contain some information 
about if it was the source or target that caused the exception to be 
thrown. Think of a copy or move operation.

How would one localize error messages if the specific exception is not 
known?

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list