Catching a specific IO error

Steve Holden steve at holdenweb.com
Tue Apr 24 08:10:43 EDT 2007


Thomas Krüger wrote:
> Tina I schrieb:
>> Now, this works but of course it catches every IOError, and I can not
>> figure out how to restrict it to only catch the "[Errno 2]"?
> 
> There's an example that uses the error number:
> http://docs.python.org/tut/node10.html#SECTION0010300000000000000000
> 
So what you'll need to do is catch all IOError exceptions, then test to 
see if you've got (one of) the particular one(s) you are interested in. 
If not then you can re-raise the same error with a bare "raise" 
statement, and any containing exception handlers will be triggered. If 
there are none then you will see the familiar traceback termination message.

regards
  Steve
-- 
Steve Holden       +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com




More information about the Python-list mailing list