Getting line number where error occured?

Jarrett Billingsley jarrett.billingsley at gmail.com
Thu Jan 15 18:06:59 PST 2009


On Thu, Jan 15, 2009 at 8:50 PM, Sergey Gromov <snake.scaly at 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.


More information about the Digitalmars-d-learn mailing list