If there’s one thing I hate about java…

September 6th, 2007

… is checked exceptions. What a pain in the ass! Who was the *brilliant* programming language engineer that thought this was a good idea? I’m starting to remember why C# was such pleasant experience…

I could go with Error approach, but that is not recommended :-(

Categories: Java | Top Of Page | 10 Comments » |

10 Responses to “If there’s one thing I hate about java…”

Diego Guidi Says:

You’re damn right!

hammett Says:

I’m sure I’m not alone on this :-D

James Kovacs Says:

It’s one of those features that looks great in demo apps, but doesn’t scale to real-world applications. The fundamental problem, as you’re probably well-aware, is that the place that you catch an exception is typically many layers removed from where you can actually handle it. This is an excellent article on the problem:

http://www.mindview.net/Etc/Discussions/CheckedExceptions

The link was given to me by Anders Hejlsberg when I asked him why checked exceptions weren’t added to C#. (They had “borrowed” most of Java’s other features.) :) When designing C#, they explicitly didn’t add checked exceptions because they weren’t seen as a good design decision in the Java world.

Rhywun Says:

I like checked Exceptions. I would rather have the compiler tell me to add an Exception than have to constantly refer to the API all day to see which Exceptions are going to inevitably be thrown or even worse wait for a crash to tell me.

Another thing I really miss from Java are default virtual methods. This trips me up every time in C#, as I have never wanted to “hide” a method, don’t understand why anyone would want to, and am sick of decorating all my code with @$#@$@ needless (to me) “virtual” and “override” keywords.

End of rant :)

hammett Says:

@James, thanks for the link. I’m sure Anders didn’t spend more than 10 minutes on this reflection :-)

@Rhywun, one thing is the language offering meta information on the exceptions a method might throw. The other is forcing you to change your API, your contracts, because at some point you dont want/should handle an exception.

About the default virtual, I think MS reply was that virtual is also part of your contract, and so is no allowing overrides. It also allows the JIT to optimize virtual/non virtual calls. Non virtuals can be inlined.

Eric Hauser Says:

Checked exceptions are pretty bad. Working with raw JDBC is probably the worst example. Fortunately, most abstraction layers wrap the checked exceptions with unchecked ones. It is pretty sad though that most exception handling ends up being:

try {
foo();
} catch (Exception e) {
throw new RuntimeException(e);
}

Pedro Teixeira Says:

I think generics implemented by type erasure is a real limiting factor (some stuff I rely on type information using reflection which can’t be done in Java). It also bothers me a bit not being able to pass an argument by ref, and not being able to create structs.

Jeff Brown Says:

La la la…

So now I’m wondering whether the next complaint will be by-ref params, generics, var-args or annotations.

OTOH, I do miss using Eclipse every day.

Markus Zywitza Says:

I don’t miss checked exceptions in C#, but withour them, I doubt we already had automatic refactoring templates (surround with try-catch) and folding in IDEs ;-))

-Markus

Luigi R. Viggiano Says:

Uncheck your checked exceptions :)

http://en.newinstance.it/2008/11/17/throwing-undeclared-checked-exceptions/

(I disagree with you, btw)

Leave a Reply