Bug 9255 – Inconsistent .file field of thrown exceptions
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-01T13:14:23Z
Last change time
2022-09-08T09:34:54Z
Keywords
pull
Assigned to
Andrej Mitrovic
Creator
Andrej Mitrovic
Comments
Comment #0 by andrej.mitrovich — 2013-01-01T13:14:23Z
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 by andrej.mitrovich — 2013-01-01T13:25:44Z
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 by andrej.mitrovich — 2013-01-01T15:20:19Z