Java: check for null or allow exception handling
<p>I'm wondering about the cost of using a try/exception to handle nulls compared to using an if statement to check for nulls first.</p>

<p>To provide more information. There's a > 50% chance of getting nulls, because in this app. it is common to have a null if no data has been entered... so to attempt a calculation using a null is commonplace. </p>

<p>This being said, would it improve performance if I use an if statement to check for null first before calculation and just not attempt the calculation in the first place, or is less expensive to just let the exception be thrown and handle it?</p>

<p>thanks for any suggestions :-)</p>

<p>Thanks for great thought provoking feedback! Here's a PSEUDOcode example to clarify the original question: </p>

<pre><code>BigDecimal value1 = null //assume value1 came from DB as null
BigDecimal divisor = new BigDecimal("2.0");

try{
    if(value1 != null){ //does this enhance performance?... &gt;50% chance that value1 WILL be null
        value1.divide(divisor);
    }
}
catch (Exception e){
    //process, log etc. the exception
    //do this EVERYTIME I get null... or use an if statement
    //to capture other exceptions.
}
</code></pre>
