[EMAIL PROTECTED] writes:

[ snip ]

> I saw the topic of using exceptions for error checking.
> I have only one response: don't
> 
> It is terribly slow as the attached code shows. These are the
> timings i've got (all times are in milliseconds):
> 
> (marcel@rincewind:0) ~/java> java Benchmark
> Time= 1821
> Time= 1681
> Time= 1356
> (marcel@rincewind:0) ~/java> java -Djava.compiler=tya Benchmark
> TYA 0.7 (for J116) loaded. Copyright (c) 1997,98 The TYA Team
> Contact  The TYA Team   via Albrecht Kleine  <[EMAIL PROTECTED]>
> Time= 1303
> Time= 1307
> Time= 165
>
> The first two times use an exception for the error condition while
> the last one uses an explicit check. Although a try/catch clause looks
> like less work on the source-code level, the JVM must do a lot more
> in this case. Therefore exceptions should only be used to the case their name
> refers to: in exceptional cases.

I thought the same way as you, until at length I came to the
conclusion that the classpath people were correct.

Your benchmark just shows that repeatedly checking for a condition
using an explicit test is faster than using a try/catch block.  This
is true, and noone is arguing against that.

The reasoning that the classpath people are using is that the
exceptional condition happens much less frequently than the normal
condition -- so, by having an explicit test you slow down *everything*
by the same amount, instead of having the possibility of having most
things running faster with an occasional slowdown in an exceptional
case.

xtoph

Reply via email to