Is throw/catch to get stack trace slow?
Ran across some code like this today:
where there's a
Wouldn't it be MUCH faster to just write this:
This would save the throw/catch. You still have to create the exception in either case, and I think the overall effect is the same, no?
public void log(String logMsg, int logFile, int priority) {
try {
throw new Exception(logMsg);
} catch (Throwable e) {
log(e, logFile, priority);
}
}
where there's a
log(Exception, int, int) method that logs the full stack trace of an exception.Wouldn't it be MUCH faster to just write this:
public void log(String logMsg, int logFile, int priority) {
Exception e = new Exception(logMsg);
log(e, logFile, priority);
}
This would save the throw/catch. You still have to create the exception in either case, and I think the overall effect is the same, no?
