Bug 3883 – Line number and file name of Exception instantiation
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-03-05T11:53:00Z
Last change time
2015-06-09T01:27:38Z
Assigned to
sean
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-03-05T11:53:25Z
I suggest to add to Exception (so later it can be shown if uncaught) the line number and file name where it was instantiated:
void foo() {
auto e = new Exception(""); // instantiation line number here
throw e;
}
void main() {
foo();
}
Exceptions get caught, rethrown, stored, etc. But in many cases they are instantiated close to where their cause is. So knowing such line number can be useful (if you are using a debugger this is not so useful).
The compiler fills such fields automatically, so the syntax usage of Exception is unchanged. Such fields can be immutable, and eventually they can be read by user code too.
The name and file name added increases the size of the Exception instances (and the binary size too a little), but I think this can't cause problems in normal programs.