What costs for sure less time for execution between the two options:
A:
if(something!=null){ ... }else{ //log } or:
B:
try{ something.getField();... }catch(Exception e){ //log } if definitely.
Throwing an exception is a costly operation and this is not the purpose of Exception.
The purpose of Exception is to catch exceptional condition that may arise at runtime but you shouldn't code to generate exception to make that decision.
Integer.parseInt() receives String qualified as Integer) Using a try{} block DOES have better performance. But when the exception is thrown more than a dozen times, regex performance is drastically better. So it seems like this is more algorithm-ended, but preferably use regex anyway. :Dif (x!=null) is perfectly predicted by the hardware it still takes 1-2cycles. While you should not be catching NPE to deal with the case, exceptions are not so slow either - esp. when the compiler can prove the stack trace is unneeded.Without even having to benchmark: Exception are ALWAYS way more expensive than programming defensively and using ifs as null-guard etc. Exceptions are always more expensive (several orders of magnitude), because the stack trace has to be generated.
Relevant SO question with benchmark: How slow are Java exceptions?
NullReferenceExceptionin java unlike c#, and you should never catch directly a NPE unless you have to make some workaround. CatchingExceptionis fine as long as you can ensure you can live with the lack of result/partial completion/etc.