I'm pretty sure try{}catch{} catch blocks add NO overhead to code,
unless the exception actually gets thrown. But exceptions are
supposed to be
exceptional, so who cares how slow it is ?
Check out how exception handling is implemented in Java byte-code
in the Java Virtual Machine Specification, 4.7.3 - The Code
Attribute.
Nick
Rachit Siamwalla wrote:
> This is funny, because a while ago (quite a while), people said that
> this code:
>
> if (intArray == null)
> return intArray[3];
> else
> return -1;
>
> was slower than this code:
>
> try{
> return intArray[3];
> }
> catch (NullPointerException e)
> {
> return -1
> }
>
> precisely because the JVM does the check for you anyway and the check
> will be done twice (unless you have a JIT), especially if the condition
> doesn't happen too often (there is still an overhead of generating the
> exception -- which is quite large).
>
> I guess times have changed :)
>
> -rchit
>
> Jim Kimball wrote:
> >
> > It was my understanding that code wrapped in an exception handler
> > introduces more overhead to the JVM. I am sure I have seen articles on
> > this exact topic in Java World or Java Report.
> >
> > Jim
> >
> > Dimitris Vyzovitis wrote:
> > >
> > > SHUDO Kazuyuki wrote:
> > >
> > > > > Personally I prefer explicit checks.
> > > >
> > > > Why?
> > > >
> > >
> > > I am also tempted to ask why....
> > > Is there any particular reason to add client side check for what the VM does on
> > > its own?
> > > I personally think that there is no need to do explicit checks in your code
> > > (it is inherently suboptimal) and let the VM do its work - just add the
> > > required exception handlers ;-}.
> > >
> > > -- dimitris
> > >
(Apologies to jim for sending you this twice).
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]