On Friday, 14 September 2018 at 14:34:36 UTC, Josphe Brigmo wrote:
Why the hell do exceptions give error in the library rather than the user code?

D exceptions can provide context in two ways:

- Stack trace, for which you need to compile with debug symbols enabled (-g).

- A file name and line number, which can be passed as parameters, and usually have the default value of the `new FileException` expression's location.

What you're seeing is the second. As you've observed, it is mainly designed to provide context when exceptions are thrown in user code, especially when debug information is not available.

Although it's possible to capture the file/line in library functions and pass them down to exception objects, it is impractical to do it for every library function. The stack trace needs to be used in such cases. Still, some functions dealing with error handling do this, e.g. std.exception.enforce.

In the future, please post questions about learning or using D in the "learn" group:

https://forum.dlang.org/group/learn

Reply via email to