Culture shock

Have I ever mentioned that I hate checked exceptions? I mean, it’s not bad when a method declares that it throws one exception type, but I’ve run across methods that throw no less than four different types of exceptions, with no common superclass between them (except Execption, no pun intended).

I’m in uncharted territory here, seeing as I’m not a hotshot Java coder, so I don’t know if this is like the worst possible thing to do. However, there are cases when there really is nothing I want to do when an exception occurs, but propagating it isn’t really a good idea either, so I’d like to swallow the exceptions and possibly log them. However, swallowing four different types looks more than a bit silly, so I ended up doing this:

} catch (Exception e) {
    if(e instanceof RuntimeException)
        throw e; // My inner C# programmer screams bloody murder at me here...

    // log error, or don't

… because I don’t want four empty catch blocks, but I really don’t want to swallow runtime exceptions either.

So. Am I off my rocker?

Leave a Reply

Your email address will not be published. Required fields are marked *