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)