I'm asking this mainly about Java, but I guess it applies to a whole host of languages.
Consider,
if(myVariable==null){
doSomethingAboutIt();
}
else carryOn(myVariable);
and
try{
carryOn(MyVariable);
}
catch(NullPointerException e ){
doSOmethingAboutIt();
}
Are both these code blocks essentially the same? Is there any reason to choose the second approach? Of course, it would be better if myVariable was never null, but it seems that the best way to check for it is to do a simple if-statement.