Exception Handling (when to use it)

Ovid publiustemp-londonpm at yahoo.com
Fri Jul 13 09:49:27 BST 2007


----- Original Message ----
From: Andy Armstrong <andy at hexten.net>

> I've seen the 'hack' of looping over a string or array and relying on
> the ArrayIndexOutOfBounds (or whatever it's called) exception to break
> out of the loop in more than one Java program.

Wow.  That really confuses me.  The person who explained to my why Java exceptions should only be used with a true exception was none other than James Duncan Davidson (you know, the guy who created Tomcat, Ant, and the Java XML API spec).  Apparently, when an exception in Java is thrown, most VMs have to do a huge amount of work collecting and serializing data and making it available in an Exception object.  If the exception is caught and the program resumes, it then has to do a lot of work with this data to ensure that the VM is in an appropriate state to resume where it left off. (Any conceptual errors here are mine, not his).

As a result, over-reliance on exceptions ensures that your Java software will often run much slower, to the point where optimization *does* become a concern.

Hmm, it would be nice if someone would start benchmarking various Perl exception handling mechanisms to make it easier to understand "best practices".

Does Perl have similar limitations?  I've never worried about it that much, to be honest.

Cheers,
Ovid
 
--
Buy the book  - http://www.oreilly.com/catalog/perlhks/
Perl and CGI  - http://users.easystreet.com/ovid/cgi_course/
Personal blog - http://publius-ovidius.livejournal.com/
Tech blog     - http://use.perl.org/~Ovid/journal/





More information about the london.pm mailing list