Exception Hierarchy [WAS: Re: Top 5]

Gide Nwawudu gide at btinternet.com
Fri Oct 10 02:06:39 PDT 2008


On Thu, 09 Oct 2008 17:21:12 -0400, Jason House
<jason.james.house at gmail.com> wrote:

>Sean Kelly Wrote:
>
>> Andrei Alexandrescu wrote:
>> > downs wrote:
>> > 
>> >> 3) the Exception/Error problem (they're different things, they
>> >> shouldn't inherit!)
>> > 
>> > I think Exception should inherit Error.
>> 
>> I personally dislike the use of "Error" to denote exceptions of any 
>> sort.  To me, errors are what /cause/ exceptions to be thrown.  For this 
>> reason, in Tango and druntime, "Exception" is defined as the top-level 
>> class from which all exceptions should derive (imagine that), making it 
>> equivalent to your "Error" object.
>> 
>> With this in mind, I'd like to solicit opinions about how exceptions 
>> should be categorized.  Should unrecoverable exceptions derive directly 
>> from "Exception" with a sibling named something like 
>> "RecoverableException" as the parent for recoverable exceptions?  Or 
>> would a bit more structure be better?  I don't think it should be the 
>> runtime's responsibility to define a complex exception hierarchy, but 
>> there is clearly a desire to at least retain some distinction between 
>> recoverable and unrecoverable errors and my naming-fu is not terribly 
>> strong.
>> 
>> 
>> Sean
>
>I think the common user case has to be catch (Exception)...
>That implies to me that Exception must extend something. My vote would be an interface with an ugly name. Then non-recoverable errors can extend that interface.  

Would something like Java's Throwable interface work and have Error
and Exception inherit from it?

http://www.artima.com/designtechniques/exceptions.html


Gide



More information about the Digitalmars-d mailing list