www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Getting line number where error occured?

reply Hoenir <mrmocool gmx.de> writes:
Might be a dumb question, but is it possible in any way to get the line 
number where an error occured?
Don't think so, but maybe I'm missing something.
Jan 14 2009
parent reply Sergey Gromov <snake.scaly gmail.com> writes:
Thu, 15 Jan 2009 02:47:07 +0100, Hoenir wrote:

 Might be a dumb question, but is it possible in any way to get the line 
 number where an error occured?
 Don't think so, but maybe I'm missing something.
assert gives a line number. There's also a keyword, __LINE__, which is an expression evaluating to the current line number, like in writefln(__LINE__); If you mean an exception stack trace then no, there's no such thing, though it's a very popular feature request.
Jan 14 2009
parent reply Bill Baxter <wbaxter gmail.com> writes:
On Thu, Jan 15, 2009 at 12:02 PM, Sergey Gromov <snake.scaly gmail.com> wrote:
 Thu, 15 Jan 2009 02:47:07 +0100, Hoenir wrote:

 Might be a dumb question, but is it possible in any way to get the line
 number where an error occured?
 Don't think so, but maybe I'm missing something.
assert gives a line number. There's also a keyword, __LINE__, which is an expression evaluating to the current line number, like in writefln(__LINE__); If you mean an exception stack trace then no, there's no such thing, though it's a very popular feature request.
Nothing built-in for this, but there are the backtrace hacks: http://team0xf.com/index.php?n=Site.Download Never tried those myself though. I use a debugger when I need a stack trace. http://ddbg.mainia.de/releases.html (Windows - on Linux I think you can use GDB). --bb
Jan 14 2009
parent reply Kagamin <spam here.lot> writes:
Bill Baxter Wrote:

 Nothing built-in for this,
 but there are the backtrace hacks: http://team0xf.com/index.php?n=Site.Download
 Never tried those myself though.
 
 I use a debugger when I need a stack trace.
 http://ddbg.mainia.de/releases.html (Windows - on Linux I think you
 can use GDB).
Weren't stack traces added to druntime some time ago?
Jan 15 2009
parent reply Sergey Gromov <snake.scaly gmail.com> writes:
Thu, 15 Jan 2009 13:08:35 -0500, Kagamin wrote:

 Bill Baxter Wrote:
 
 Nothing built-in for this,
 but there are the backtrace hacks: http://team0xf.com/index.php?n=Site.Download
 Never tried those myself though.
 
 I use a debugger when I need a stack trace.
 http://ddbg.mainia.de/releases.html (Windows - on Linux I think you
 can use GDB).
Weren't stack traces added to druntime some time ago?
You're correct, I missed that. Exception is derived from Throwable in druntime, and Throwable has a field 'info' of type TraceInfo with opApply in its interface. But it doesn't work, at least with DMD 2.023 on Windows. Attempts to access this field cause object.Error: Access Violation. I didn't try to investigate further though.
Jan 15 2009
next sibling parent Bill Baxter <wbaxter gmail.com> writes:
On Fri, Jan 16, 2009 at 10:50 AM, Sergey Gromov <snake.scaly gmail.com> wrote:
 Thu, 15 Jan 2009 13:08:35 -0500, Kagamin wrote:

 Bill Baxter Wrote:

 Nothing built-in for this,
 but there are the backtrace hacks: http://team0xf.com/index.php?n=Site.Download
 Never tried those myself though.

 I use a debugger when I need a stack trace.
 http://ddbg.mainia.de/releases.html (Windows - on Linux I think you
 can use GDB).
Weren't stack traces added to druntime some time ago?
You're correct, I missed that. Exception is derived from Throwable in druntime, and Throwable has a field 'info' of type TraceInfo with opApply in its interface. But it doesn't work, at least with DMD 2.023 on Windows. Attempts to access this field cause object.Error: Access Violation. I didn't try to investigate further though.
And also, D1 will not be moved to the new common druntime, so if you're using D1 then backtrace hacks or a debugger are still your only options I think. --bb
Jan 15 2009
prev sibling parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Thu, Jan 15, 2009 at 8:50 PM, Sergey Gromov <snake.scaly gmail.com> wrote:
 You're correct, I missed that.  Exception is derived from Throwable in
 druntime, and Throwable has a field 'info' of type TraceInfo with
 opApply in its interface.

 But it doesn't work, at least with DMD 2.023 on Windows.  Attempts to
 access this field cause object.Error: Access Violation.  I didn't try to
 investigate further though.
By default there is no mechanism to fill in this info, so it's null. The "proper" usage would be something like: if(ex.info) writefln("Traceback: %s", ex.info); But again, there is no mechanism to fill this in, only the hooks to make it possible to do so. Team0xf has made a few traceback modules which work only with Tango on Windows to fill in this info, but there's no reason it couldn't be done on other platforms or with Phobos.
Jan 15 2009
parent reply Hoenir <mrmocool gmx.de> writes:
Jarrett Billingsley schrieb:
 Team0xf has made a few traceback modules which work only with Tango on
 Windows to fill in this info, but there's no reason it couldn't be
 done on other platforms or with Phobos.
only with Tango? I've also seen some Phobos hacks on their site.
Jan 15 2009
parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Fri, Jan 16, 2009 at 2:40 AM, Hoenir <mrmocool gmx.de> wrote:
 Jarrett Billingsley schrieb:
 Team0xf has made a few traceback modules which work only with Tango on
 Windows to fill in this info, but there's no reason it couldn't be
 done on other platforms or with Phobos.
only with Tango? I've also seen some Phobos hacks on their site.
The Phobos backtrace hack on team0xf's site is for D1. Since D2 now uses druntime, they wouldn't work, but an approach similar/identical to the Tango backtracers would.
Jan 16 2009