exception messages

Greg greg.steffensen at gmail.com
Tue Oct 23 18:09:37 PDT 2012


Awesome, that's more informative than the API docs would have 
been anyway.

BTW, another API docs problem I noticed is that on the main page, 
the module list in the sidebar doesn't match the module list in 
the page content (the sidebar has more modules, including 
std.exception).

Thanks!

On Wednesday, 24 October 2012 at 01:03:12 UTC, Andrej Mitrovic 
wrote:
> On 10/24/12, Greg <greg.steffensen at gmail.com> wrote:
>> I'm attempting to learn D through a personal project, and can't
>> figure out how to get the message from an exception.
>
> I don't know why Throwable is not documented
> (http://dlang.org/phobos/object.html#Throwable), but you can 
> use the
> .msg field:
>
> import std.exception;
> import std.stdio;
>
> void main()
> {
>     try {
>         enforce(0, "message");
>     }
>     catch (Exception ex)
>     {
>         writeln(ex.msg);
>     }
> }
>
> See the DMD2/src/druntime/src/object_.d file for the class 
> definition
> of Throwable and Exception, Throwable has these fields:
>
>     string      msg;
>     string      file;
>     size_t      line;
>     TraceInfo   info;
>     Throwable   next;




More information about the Digitalmars-d-learn mailing list