I know
throw new Exception();
has a pretty large overhead, since it creates a full stackTrace, etc.
Does
throw new Thr
Nope, you need your own subclass to avoid that effect.
Exception ex = new Exception() {
@Override public Throwable fillInStackTrace() {
return this; // and do nothing else
}
};
This creates an instance of exception that will not fill the stack trace (the creation of exceptions delegates to fillInStackTrace
to actually fill the stack trace) and is thus cheap to create.