January 2004 Archives

Swallowed Exceptions Are Evil


I was wondering why the program was failing silently. Eventually I tracked it down to this:

	} catch (Exception e) {
	    return null;

Argh! I understand that whoever wrote this probably does not intend harm, but it does no favours to any programmers who are trying to fix problems later.

I suspect this is a case of the law of unintended consequences, as discussed by Bruce Eckel amongst others. Exceptions that a programmer must declare or handle should encourage discipline and careful design. However, given human nature and the pressure to get things done, it's too easy to write a catch clause that just ignores the problem.

Note to self: no matter how unlikely I think some scenario is, I must never just swallow an exception.

Here's what I should do, from best to worst.

Avoid the exception altogether.
Mainly, this means designing the program so that users cannot go down a path where they will trip. There is a danger that power users might feel constrained, but in any case the obvious actions should not lead to errors. It's hard to guide users when the program has to interact with an external environment over which the programmer has no control.
Fix the problem automatically without making a fuss
It's tempting as a programmer to highlight how clever the code is to be able to recover; it's usually best to resist the urge.
Report the error
Again, the program should not make too much fuss. If the program is utterly stuck and there is no way to get anything to work, a prominent error message is appropriate. If there's a minor glitch, a subtler and less intrusive message may be called for.
Log the error
The much maligned System.err.println() has its uses. At the very least it gives a programmer something to grep for. With Java there are at least a couple of decent choices for logging.

As a user, I want to know if something went wrong. A program that fails silently is worse than one that fails with a cryptic error message.

As a programmer, I want to know what went wrong. It doesn't matter if I can't immediately figure out what it is: I just want enough to point me to the right place to look in the code.

We Are Fostering Cats

Mazzy and Clark arrived today and are settling in. She's black and white and he's a white and orange tabby. So far they seem happy enough; Clark even purrs when S. strokes him. They're house cats, so we're optimistic they'll like our apartment. There's a sun room with lots of windows so they can look at the squirrels and other passersby.

Software and Cargo Cult Science

| No Comments

Jef Raskin writes about superstitious behavior in the technological world:

Computer systems exhibit all the behaviors best suited to create superstitious responses. You will try something, it won't work, so you try it again — the exact same way — and this time it works, or not. That's random reinforcement. The effectiveness of many programming and management practices thus are not measurable.

Richard Feynman wrote about pseudoscience in his book Surely You're Joking, Mr. Feynman. [alternative]

That book and a follow-up called What Do You Care What Other People Think, are probably among the most enjoyable I've read about science. That's mainly because they're full of stories that stand on their own merits as entertainment. The science is there, but it's mostly in the background, as a way of thinking that Feynman is able to use in his adventures.

There's one piece at the end of Surely You're Joking that is more serious in tone, his talk on cargo cult science. The parable has its limitations. I have a hard time imagining south sea islanders who build a cult around trying to attract the cargo planes as if they were a supernatural phenomenon. Never mind, the talk is worth reading in full.

I'm Engaged


No, we don't know when the wedding will be. Probably in Chicago; probably in 2004; probably not too fancy.

I popped the question on New Year's Day, shortly after midnight. We had friends present who can verify that we were both compos mentis.

I did feel high for a few days, as if I had taken some proscribed, mood-altering substance. It's strange to experience physical emotions, almost tangible, that feel so involuntary, so unexpected.