digitalmars.D.learn - exception messages
- Greg (9/9) Oct 23 2012 I'm attempting to learn D through a personal project, and can't
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (9/17) Oct 23 2012 There is a ddoc problem at dlang.org but it is defined in object.d:
- Andrej Mitrovic (23/25) Oct 23 2012 I don't know why Throwable is not documented
- Greg (9/36) Oct 23 2012 Awesome, that's more informative than the API docs would have
- H. S. Teoh (9/16) Oct 23 2012 [...]
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
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
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
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
On Wed, Oct 24, 2012 at 03:03:02AM +0200, Andrej Mitrovic wrote:On 10/24/12, Greg <greg.steffensen gmail.com> wrote:[...] 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.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:
Oct 23 2012