try... except with unknown error types

Roy Smith roy at panix.com
Sun Aug 21 17:14:30 EDT 2011


In article <7xty9ahb84.fsf at ruckus.brouhaha.com>,
 Paul Rubin <no.email at nospam.invalid> wrote:

> It's a retail application that would cause some business disruption and
> a pissed off customer if the program went down.  Also it's in an
> embedded box on a customer site.  It's not in Antarctica or anything
> like that, but it's a few towns over, and someone would have to drive
> there (probably through heavy traffic) if something went wrong that
> power cycling the box couldn't fix.

I would do something like this:

try:
   do_some_network_stuff()
except IOError:
   do_normal_recovery()
except Exception:
   call_home()
   do_some_other_recovery()

You are right, in an embedded/unattended application, you don't want to 
ever crash.  If you ever get an error that you don't understand, you 
have no choice but to do the best you can to recover.  I would also 
generate some kind of alert back to home base to tell somebody to take a 
look at it and make sure things are fine.

I would expect that the whole application is wrapped in some kind of 
watchdog timer which will do a hard reset of the entire system.



More information about the Python-list mailing list