Is invocation of exception.fillInStacktrace useful?

java, stack-trace

Solution

You are correct on both counts: the biggest reason why `fillInStackTrace` is even available is to let you override it in your own exceptions where you'd like to save the costs of providing the stack trace information, or where you need to hide the information about the location from which the exception may have been thrown. See this answer for more details.

Problem

I found an explicit invocation of `e.fillInStacktrace()` directly after creation of the exception `Exception e = new Exception()`. I think this is redundant, because the constructor of `Throwable` already invoke `fillInStacktrace()`. But maybe I overlooked something and this lines are useful: ``` Exception e = new Exception(); e.fillInStackTrace(); creationInfo = new CreationInfo(e.getStackTrace()); ``` (`public CreationInfo(StackTraceElement[] aStackTrace){...}`) I think the additional invocation of `e.fillInStackTrace();` directly after creation an exception is redundant and will wast a lot of resource, because this method is expensive. It seams that this construct is only needed to obtain the current stacktrace, therefore: ``` creationInfo = Thread.currentThread().getStackTrace(); ``` is the better way. Before filling an issue report I want to ask you if I have overlooked something?

Original source

Related problems