Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday November 02, 2004
12:32 AM

Java exceptions, exceptions, exceptions

[ #21641 ]

Frankly, I find avoiding duplicate code in Java to be a pain. I can't tell you how many times my perfectly sensible refactor has been tripped up by exception handling. I'd love to be able to pass around deferred bits of code. No such luck. In my database code, I seem to have a few sections of code that have identical try/catch blocks around them, but since the code on the inside of the try block is not the same, I can't seem to pull it out -- unless I wrap it in the try/catch blocks I'm trying to refactor. Am I just not getting the hang of software design in Java or is it always this bad?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Using unchecked exceptions for this helps a lot. Take a look at what the Spring Framework [springframework.com] has done merging ORM and JDBC exceptions into a single unchecked hierarchy. Makes for very clean code, particularly if you use their *Template classes (JdbcTemplate, HibernateTemplate, ...).
    • Er, are you saying that my design doesn't have a fundamental flaw? I find it hard to believe that a language is set up in such a way that I can't factor out common code.

      • No, I'm just saying that one way around it is unchecked exceptions. I can't say one way or another about your design without actually seeing it :-) Unchecked exceptions can also be a way of sweeping problems under the rug.

        But the Spring items I mentioned earlier are one way to get around these sorts of design issues even if you don't consider the unchecked exception part. There are a couple of examples at devx [devx.com], and the Spring docs (esp. the PDF [springframework.org]) are generally excellent and have examples as well. (See sect