[Tutor] how to catch particular Errno for Exceptions
sigurd at 12move.de
Mon Apr 5 21:17:19 EDT 2004
On 6 Apr 2004, Brian van den Broek <- bvande at po-box.mcgill.ca wrote:
> how do I catch a specific Errno for an exception?
I don't think this can be done.
> I have no G: drive and have tried the following code:
> import os
> except OSError:
> print 'OSError caught!'
> except OSError, (2,): #what to write here?
> print 'OSError Errno 2 caught!'
> The first works try clause just fine, the second gives me a "can't
> assign to a literal" error when I try to run it out of IDLE. I've
That's clear. It tries to assign the error number to `2' which happens
to be a literal value.
If you want to know the eeror number adfterwards it's written clearly in
the Tutorial how to achieve that.
> Also, I've just posted three questions all on related, but
> distinct topics. Most list I am on prefer 3 msgs in such
> situations. Would it be preferred that I had posted all in one?
I can only speak for myself: IMO it was absolutely rihgt the way you did
Please do *not* send copies of replies to me.
I read the list
More information about the Tutor