Would it be benefical to add a generic way to add info to a Throwable without creating a new Throwable?
I often see code like this:
try {
foo();
} catch(Exception e) {
throw new Exception(e.getMessage() + " extra info=" + blah, e);
}
Would it be better to instead add Throwable.setProperty(String key, String value) so that the code above becomes the following?
try {
foo();
} catch(Exception e) {
e.setProperty("extra info", blah);
throw e;
}
The extra info could print (one per line) between the message and stack list.
Benefits: 1. Would not require creating new Throwables just to add extra information. 2. Stack traces would not have multiple layers of cause traces (and therefore be easier to read) 3. Reduce cost of creating extra stack traces.