D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9255 - Inconsistent .file field of thrown exceptions
Summary: Inconsistent .file field of thrown exceptions
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Andrej Mitrovic
URL: https://github.com/D-Programming-Lang...
Keywords: pull
Depends on:
Blocks:
 
Reported: 2013-01-01 13:14 UTC by Andrej Mitrovic
Modified: 2022-09-08 09:34 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2013-01-01 13:14:23 UTC
module foo.bar;

import core.exception;
import std.stdio;

void main()
{
    try
    {
        assert(0);
    }
    catch (Throwable e)
    {
        writeln(e.file);
    }

    try
    {
        throw new Exception("");
    }
    catch (Throwable e)
    {
        writeln(e.file);
    }
}

$ rdmd test.d

foo.bar
test.d

The assert sets the 'file' field to the module name, whereas an Exception sets it to the file name. This makes it hard to parse the file field in order to produce error messages which can further be parsed by e.g. editors or IDE tools (for example double-click on a unittest failure message could automatically open a file, *if* the path is actually valid).
Comment 1 Andrej Mitrovic 2013-01-01 13:25:44 UTC
In my codebase even assert() itself is inconsistent with itself, I don't know why. Sometimes it uses the module name, other times the file name. I guess the best thing to do is use a wrapper which throws AssertError on its own until this issue is fixed.
Comment 2 Andrej Mitrovic 2013-01-01 15:20:19 UTC
https://github.com/D-Programming-Language/dmd/pull/1426
Comment 3 RazvanN 2022-09-08 09:34:54 UTC
This has been fixed by: https://github.com/dlang/dmd/pull/8517