Software Carpentry

Helping scientists make better software since 1997

Error Handling

One topic that isn’t currently in the curriculum that I’d really like to add is detecting, handling, reporting, and recovering from errors. This makes up is 10-30% of the code in real applications, but dealing with errors is almost omitted from textbook examples and tutorials for the sake of clarity  (Tanenbaum’s Minix book being a laudable exception).  I have asked elsewhere for someone to write an entire book on the subject; if anyone wants to take a crack at an hour-long lecture, please get in touch.

Advertisements

Written by Greg Wilson

2009/05/12 at 23:58

Posted in Content

One Response

Subscribe to comments with RSS.

  1. So you caught an exception or got an error return code… now what?

    The “error handling” coding exercises in my undergrad were good for the mechanics — we walked through the various methods of error code checking, exception catching, and assertions. Then, in my first few programming jobs, the consequences of good-or-bad error-handling schemes was usually on someone else — the QA department or the support department or the technical manual writing department. As long as everything was caught and analyzed it was satisfactory for the course grade or the term review.

    It wasn’t until I started my entrepreneurial adventures that I encountered the real “error handling,” something like this:

    You will launch your code tomorrow.
    1,000,000 customers will download it.
    They have your phone number.

    Now, “error handling”-so-you-can-sleep should be broken down into a few different goals:

    – make the software work as well as it can in more situations for more people
    – help customers determine where and why something unexpected happened, let them know what to do
    – help maintainers track down faults
    – determine that the system is in a bad state as soon as possible
    – don’t erase or break anything else

    Knowing which goal you’re pursuing in what code is the basis for your error handling tactics: Sometimes you ignore it. Sometimes you try something else. Sometimes you escalate.

    Bogdan Chmielewski

    2009/05/15 at 22:09


Comments are closed.

%d bloggers like this: