exception types & objects

Lutger lutger.blijdestijn at gmail.com
Wed Oct 20 00:53:57 PDT 2010


spir wrote:

> On Tue, 19 Oct 2010 14:52:20 +0200
> "Simen kjaeraas" <simen.kjaras at gmail.com> wrote:
> 
>> > I was expecting (from exp with other language) there to be a root
>> > Error or Exception type implementating base exception mechanics and/or
>> > an imposed interface to comply with (esp a kind of string method
>> > returning what text to write out when the exception is not caught).
>> > How does this work, and how to use it concretely?
>> 
>> There is a base class Exception and Error, as well as the base interface
>> Throwable, which the aforementioned implement. Using this is more of a
>> convention than absolute necessity, but it is used all over Phobos and
>> druntime, and it is heavily discouraged not to use those as bases.
> 
> Good. Is this documented somewhere (have searched language and library
> references before asking: found some documents on peculiar aspects, but
> none describing the mechanism and how to use).

Unfortunately the relevant docs here seem to be a bit out of date.

look up nothrow:
http://www.digitalmars.com/d/2.0/function.html

this is out of date wrt the throwable hierarchy:
http://www.digitalmars.com/d/2.0/errors.html

contains related info, recommended:
http://www.digitalmars.com/d/2.0/exception-safe.html

If you want more details you could look up the header files of druntime 
distributed with the dmd package, specifically:

src/druntime/import/object.di: contains the Throwable, Error and Exception 
interfaces

src/druntime/import/core/exception.di: contains a few derived Exceptions


More information about the Digitalmars-d-learn mailing list