exception types & objects

Stewart Gordon smjg_1998 at yahoo.com
Tue Oct 19 12:36:23 PDT 2010


On 19/10/2010 13:13, spir wrote:
<snip>
> The example uses an Excpetion type, but the somewhat comment
> contradicts it. Can one really use any kind of object as exception?

Yes.

> How does D then handle it?

The mechanism is class-agnostic.  The only thing it relies on is that 
it's an object of some class type.

> 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

Imposed interface to do what with the exception?

OK, so I can think of one example it would be nice to have: stack 
traces.  This could be implemented in Exception, I suppose.  But still, 
restricting throw to this class would be a puristic rather than 
practical step forward.

> (esp a kind of string method returning what text to write out when
> the exception is not caught).
<snip>

Object.toString()

Stewart.


More information about the Digitalmars-d-learn mailing list