3 ms·
> Throwing an exception in Java is a non-trivial expense since the constructor for Throwable populates a stack-trace structure for the current thread. If you're
by cesarb 8y ago
> Throwing an exception in Java is a non-trivial expense since the constructor for Throwable populates a stack-trace structure for the current thread. If you're using exceptions as a routine flow-control mechanism, you're incurring that cost too frequently.
Unfortunately, the JVM has special code to detect this case (!) and stop recording the stack trace after a while (!!). Then when you go look at your log to see why the system isn't working, you see only `NullPointerException` without the expected stack trace, and you have to guess where it's coming from (after wondering for a few hours why the stack trace went missing, only to find the explanation at https://stackoverflow.com/questions/2411487/nullpointerexception-in-java-with-no-stacktrace/3010106#3010106 https://stackoverflow.com/questions/2411487/nullpointerexcep...).
- bunderbunder 8y agoThe fact that anyone ever thought it would be worthwhile to implement an optimization like this is very telling. I'm not exactly sure what it tells us, but it definitely tells us something.