Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
January 15, 2009 Getting line number where error occured? | ||||
---|---|---|---|---|
| ||||
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. |
January 15, 2009 Re: Getting line number where error occured? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hoenir | 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.
|
January 15, 2009 Re: Getting line number where error occured? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sergey Gromov | 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 |
January 15, 2009 Re: Getting line number where error occured? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | 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?
|
January 16, 2009 Re: Getting line number where error occured? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | 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.
|
January 16, 2009 Re: Getting line number where error occured? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sergey Gromov | 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
|
January 16, 2009 Re: Getting line number where error occured? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sergey Gromov | 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.
|
January 16, 2009 Re: Getting line number where error occured? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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.
|
January 16, 2009 Re: Getting line number where error occured? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hoenir | 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.
|
Copyright © 1999-2021 by the D Language Foundation