>>>>> "Stuart" == Stuart Ballard <[EMAIL PROTECTED]> writes:
>> Catching exceptions is extremely slow, as is anything in general
>> which has to do with exceptions. I would say that the second idiom
>> should always be favoured.
Stuart> It depends - suppose catching an exception is 100 times slower
Stuart> than doing a comparision to null. And then suppose that you
Stuart> hardly ever expect the value to be null - only, say, 1 in 1000
Stuart> times.
Stuart> [ ... ]
It's worse than this, even, because these factors vary from
implementation to implementation.
For instance, with gcj the penalty for the null check is absurdly
small, and exceptions are relatively heavyweight -- at least, when the
code is compiled. When interpreted the overhead for the null check is
higher (as compared to the compiled case). And if we write a JIT we
might get a third tradeoff.
I personally prefer the explicit check. The try-catch form might mask
bugs in the actual security manager. It also seems a bit more
convoluted, but of course that is a matter of taste.
Tom