www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - exception messages

reply "Greg" <greg.steffensen gmail.com> writes:
I'm attempting to learn D through a personal project, and can't 
figure out how to get the message from an exception.  I've 
basically defined a custom subclass of Exception to represent 
when invalid inputs are provided, and would like to have a master 
catch block that handles them, but I can't find API docs for 
Throwable or Exception within the Phobos Library Reference.   In 
particular, I can't find API definitions for those classes in 
either std.exception or core.exception.  Where else should I be 
looking?
Oct 23 2012
next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 10/23/2012 05:51 PM, Greg 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've basically defined a
 custom subclass of Exception to represent when invalid inputs are
 provided, and would like to have a master catch block that handles them,
 but I can't find API docs for Throwable or Exception within the Phobos
 Library Reference. In particular, I can't find API definitions for those
 classes in either std.exception or core.exception. Where else should I
 be looking?
There is a ddoc problem at dlang.org but it is defined in object.d: http://dlang.org/phobos/object.html#Throwable On my system, the .di of that module is found here: /usr/include/d/dmd/druntime/import/object.di Here is the current version of the file: https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d Ali
Oct 23 2012
prev sibling next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 10/24/12, Greg <greg.steffensen 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;
Oct 23 2012
parent "Greg" <greg.steffensen gmail.com> writes:
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 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;
Oct 23 2012
prev sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Oct 24, 2012 at 03:03:02AM +0200, Andrej Mitrovic wrote:
 On 10/24/12, Greg <greg.steffensen 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:
[...] Neither Throwable nor Exception are adequately documented. I decided to remedy that: https://github.com/D-Programming-Language/druntime/pull/337 :) T -- Life is unfair. Ask too much from it, and it may decide you don't deserve what you have now either.
Oct 23 2012