Cost of having try-catch statements?

Ranjit Mathew rmathew@gmail.com
Wed Aug 11 06:55:00 GMT 2004


Martin Egholm Nielsen wrote:
> Hi there,
> 
> I was wondering: Is there any significant cost in having "unused" 
> try-catches in my code?
> That is, I have a method that 99.99% of the times invoked never throws a 
> given exception. However, in case it does, I need to log it...

You have not mentioned the platform you have in mind.

On almost all of the major platforms, GCC uses DWARF-2
unwind information based exception handling ("range tables")
which involves almost no performance overhead in the
"normal" case.

GCC builds for Windows from MinGW (www.mingw.org) however
use SJLJ (setjmp-longjmp) based exception handling which
does involve an overhead even in the "normal" case. This
is needed at the moment to correctly unwind over a Windows
events callback stack. I am not sure, but probably Cygwin
builds are also built like this.

You can find an excellent overview of these approaches
in this paper:

http://www.usenix.org/events/osdi2000/wiess2000/full_papers/dinechin/dinechin_html/

Ranjit.

-- 
Ranjit Mathew          Email: rmathew AT gmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/



More information about the Java mailing list