Exception handling patterns/techniques

Discussion in 'Java' started by James L, Mar 5, 2008.

  1. James L

    James L Guest

    How do you all feel about the commonly-seen technique of exception
    wrapping? It can keep interfaces clean - but then you end up breaking
    compile-time exception handling checking, as pointed out here:

    http://weblogs.java.net/blog/bakksjo/archive/2005/09/java_exception.html

    (and you risk never dealing with exceptions that are added to the code
    later on...)

    Also, suppose I have a class that contains ten methods, each of which do
    something similar (e.g. comms) which can throw the same five exceptions
    each time. Is there a handy pattern for refactoring those five catch
    statements into one place, if such a thing were desirable?[1] (This is
    maybe drifting into the area of aspect-oriented programming...)

    One naive way might be to have each of the ten methods call a single
    method with parameters, which contains a switch which calls the correct
    ultimate target method - then you just have one try...catch wrapping
    that switch statement. This is pretty ugly though.


    [1] I realise that such a thing might very rarely be actually desirable!

    thanks,
    J
    James L, Mar 5, 2008
    #1
    1. Advertising

  2. James L

    Mark Space Guest

    James L wrote:
    > How do you all feel about the commonly-seen technique of exception
    > wrapping? It can keep interfaces clean - but then you end up breaking
    > compile-time exception handling checking, as pointed out here:


    I've heard a rumor that Java 7 will contain some sort of official
    support for wrapping exceptions. I'm kinda bummed about that, since I
    don't think it will encourage clean code to be written, but I guess
    market pressure is pushing Sun into it.
    Mark Space, Mar 5, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. metsys
    Replies:
    1
    Views:
    761
    =?Utf-8?B?RFdT?=
    May 4, 2006
  2. crichmon
    Replies:
    4
    Views:
    471
    Mabden
    Jul 7, 2004
  3. Sean Abrahams

    Web Form Error Handling Techniques

    Sean Abrahams, Jan 16, 2004, in forum: Python
    Replies:
    1
    Views:
    355
    Samuel Walters
    Jan 18, 2004
  4. Timasmith

    exception handling patterns?

    Timasmith, Oct 17, 2006, in forum: Java
    Replies:
    1
    Views:
    272
    Oliver Wong
    Oct 17, 2006
  5. snarf
    Replies:
    7
    Views:
    99
Loading...

Share This Page