Re: Exceptions no longer incur overhead?



void.no.spam.com@xxxxxxxxx wrote:
One of our classes has a method to look up an object. If the object
does not exist, it throws an exception to indicate that. I thought it
would be better to just return null, as exceptions incur overhead. I
talked to the senior java developer who wrote the class, and he said
that recent versions of Java have improved exceptions to the point
that they do not really incur any overhead. Is this true?

In some circumstances exceptions *throws* can be optimised away. Explicitly creating an exception, however, is expensive. Mostly in creating the stack trace.

Anyway, the general approach is to write code to be well written. Then test performance in real world situations.

Tom Hawtin
.