Like quite a few people, I'm going to add my voice to the throng and say that Joel Spolsky's latest essay, Exceptions, is the first of his writings that I can remember looking at and thinking, “Man, that's just wrong.”
The reasoning is that I consider exceptions to be no better than "goto's", considered harmful since the 1960s, in that they create an abrupt jump from one point of code to another. In fact they are significantly worse than goto's
I could go into what is good about exceptions at great length, but it's already been well dealt with elsewhere in great detail.
- C2 Wiki: Use Exceptions Instead Of Error Values
The only alternative I know of to exceptions is to wrap every function in an if statement and either return with an error code or completely exit the program. The result is code whose purpose is more focussed on returning error codes than performing its desired function. I've had to work with well written code that was written in this style and it becomes very difficult to understand the code. When needed (which is not that often), exceptions provide an excellent alternative way of returning errors and they do not lead to clutter throughout the code.
- Ned Batchelder
OK, so usually Joel Spolsky is a pretty bright guy, and even when his ideas seem wacky or overstated, there's something true and useful about them. But he's dead wrong about exceptions.
- James Robertson
Bleah . I've seen code written using that theory. It very, very quickly becomes an unmaintainable nightmare, and has errors being propagated from deep in the bowels of the application up to a level where they can be handled. This is clean how?
- Ben Poole
OK, so I know I'm a newbie at this object oriented thang, but I remember when I first learned about exceptions in Java, and how they work. As someone who was getting pretty tired of On Error Goto lblErrs..., it struck a chord let me tell you!
- Keith Pitty
As a counterpoint, I think Rebecca Wirfs-Brock's article entitled "What It Really takes to Handle Exceptional Conditions", presented at the forUSE 2002 conference, makes worthwhile reading.
- Various Posters on Joel's Message-Board
The problem with return codes is it's just SO easy to forget to check them. You forget to check a return code even once, and you've got a big fat hole in your program...
...I must say also, this is first thing I strongly disagree with Joel on. I do abhor checked exceptions as the ivory tower approach. But unchecked exceptions make code far easier to write and read....
...Joel's site must have been hacked. Either that or he's being sarcastic.