Cost of having try-catch statements?

Reshat Sabiq
Mon Aug 23 23:02:00 GMT 2004

> Eh.  Maybe my mind is going, but I thought I'd seen a patch to unwind
> over Windows callbacks.

> Andrew.

This was my question for the past couple of days as well. While i'm not
versed in the machine language instructions involved, i expected the
overhead to be minimal, just by thinking how i would implement exception
I would like to ask what platform was the 4-5 times overhead seen on in
Windows? I just tried the same Main class mentioned by Harald on both
Windows 2000 and Windows XP using SDK 1.3.1_05. After averaging 10
executions, the overhead i've seen on 2000 is 8.55%, and on XP it is
2.47%. If we considered a method with millions or billions of instructions
inside, the overhead would be totally miniscule.
The times i'm getting w/ try-catch are 297.65ms on 2000, and 223.75ms on

In general, based on this simple test and the common sense, i'm concluding
that it is safe to assume that try-catch w/o the exception thrown has
negligible overhead. While i'm cognizant of GCC builds for Windows from
MinGW mentioned by Ranjit, that doesn't appeat to apply in most other
applicable cases, such as when using the regular Sun JVMs and bye-code.


More information about the Java mailing list