D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3129 - Cannot take advantage of overriding Throwable.toString
Summary: Cannot take advantage of overriding Throwable.toString
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Sean Kelly
URL: http://www.dsource.org/projects/drunt...
Keywords: bootcamp, patch
Depends on:
Blocks:
 
Reported: 2009-07-02 06:09 UTC by anonymous4
Modified: 2021-01-09 22:46 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description anonymous4 2009-07-02 06:09:29 UTC
It's a pain when you set Throwable.file, toString function is completely bypassed by catching block in tryExec, so you can't do posponed error message generation. AFAIK, only Error takes advantage of setting file field, so it makes sense to restrict default error output to instances of Error class. No need to worry about losing this functionality since equivalent code is already in Throwable.toString.

dmain2.d, line 324
---
- if (e.file)
+ if (e.file && cast(Error)e)
---

Another minor issue is that both Throwable.toString and tryExec iterate through nested exceptions and output trace contexts, so if file field is not set, both of them are executed resulting into duplication of exception info.
Comment 1 anonymous4 2009-07-02 06:14:37 UTC
Another possible solution is to change line 320
---
- catch (Throwable e)
+ catch (Error e)
---

so that unoverridden Throwable.toString is executed in catch(Object o) block.
Comment 2 Tiberiu Lepadatu 2018-10-21 14:17:30 UTC
Bug not reproducible.
Comment 3 Mathias LANG 2021-01-09 22:46:15 UTC
Indeed, the code has greatly evolved since then and we can mark this as WORKSFORME.