I would like to override fillInStackTrace
as a performance improvement, since I won't be needing the stack trace for my Exception. What's the correct way to do this?
The first method calls super()
in the constructor, and the second does not. Does this make a difference?
If I call super()
in the constructor, will the overridden fillInStackTrace
be called, or will the fillInStackTrace
from the superclass be called?
to
I believe both methods are correct (in which case calling super
is preferable) but I want to be sure.
Method 1
public class MyException extends Exception {
public MyException() {
super();
}
@Override
public Throwable fillInStackTrace() {
return this;
}
}
Method 2
public class MyException extends Exception {
public MyException() {}
@Override
public Throwable fillInStackTrace() {
return this;
}
}