Taking Exception to Joel Spolsky

October 14, 2003 7:11 PM

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.

1 TrackBacks

Listed below are links to blogs that reference this entry: Taking Exception to Joel Spolsky.

TrackBack URL for this entry: http://fishbowl.pastiche.org/mt-tb.cgi/389

In his most recent article, Joel Spolsky declares that exceptions are bad. He's gotten a lot of pushback on this (Charles Miller has a nice collection of this), which is not surprising. Many of us have worked with error return... Read More

7 Comments

I honestly even read the whole article after reading "exceptions are gotos". I believe that exceptions are far more elegant solution than what he proposes using error codes. I believe that what he is proposing is filling up elegant and simple code to read with a bunch of "if then else" statements.

What we don't know is that he was smoking pot while he was writing the post.

I honestly even read the whole article after reading "exceptions are gotos". I believe that exceptions are far more elegant solution than what he proposes using error codes. I believe that what he is proposing is filling up elegant and simple code to read with a bunch of "if then else" statements.

What we don't know is that he was smoking pot while he was writing the post.

What's wrong with goto? For error handling, they're golden. If you don't believe me, take a look at the Linux source code - this is the most actively developed codebase on earth, and one reason it's manageable by hundreds if not thousands of deveolpers is that the judicious use of gotos, used only for error conditions, make it very clear what's going on. I cringe to think what would happen if exceptions were used, not to mention Spolski's brain-dead alternative.

Okay, I'm a neophyte, with less than three years of real-world programming on my resume. So normally I give Mr. Spolsky a fair amount of credit on his opinions. This time, however, I have to admit that I don't know where he's coming from. After learning/working in BASIC, C, C++, and (especially) Visual Basic and Java, I didn't have any problems understanding or using exceptions, and in fact have found it *very* useful to write custom exceptions to check/enforce business logic. In this sense, I don't see any difference between custom error codes and custom exceptions.

Maybe that's just ignorance/inexperience talking. I don't typically write multi-threaded code and I usually don't have to write for anyone who wouldn't understand the rationale behind an exception (and thus wouldn't know how to deal with it). And I'm pretty anal about documenting my code. All that probably explains my perspective.

This fishbowls comment states "... I ... 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.'".

No, you and all the others are just plain wrong, and Joel is right.

The catatrophic effect of the sheer existence of exceptions is, that they prohibit to _understand_ the behaviour of code sections just by reading them.

It is something all you part-time programmers are ignorant about. We talk about it in 10 years from now, where exceptions will be banned like gotos ara now.

Volker Glave

"Part-time programmers?" There is almost certainly more cumulative, professional programming experience referenced in the post above than you have years on this earth.

I welcome constructive debate, but there's no cause to be discourteous.

> I welcome constructive debate, but there's no cause to be discourteous.

The debate is spanning years right now. You cannot be constructive all the time.

The thing is this. We have exceptions. One part of the community think they do more good than evil. Other (smaller) part (me include) think they do more evil than good. Not both parts can be true, one part has to be wrong. (So was the story with gotos, the result we know and accept [ok, 99 %].) Since the are even smart guys [tm] in both parts, can please these guys stick their heads together and reason this out once and forever, so that we everday programmers can get back to work and do not have to talk exceptions day in and day out (as is the case here as in my current project)? Thanks.

Previously: Money Laundering

Next: Google, Weblogs, and the End of the World