added "except Exception, e:" example.
don't *ever* use a too general exception class, CatchWhatYouCanHandle
|Deletions are marked like this.||Additions are marked like this.|
|Line 10:||Line 10:|
z = "divide by zero"
print "divide by zero"
|Line 21:||Line 21:|
|except Exception, e:||except ZeroDivisionError, e:|
The simplest way to handle exceptions is with a "try-except" block:
If you wanted to examine the exception from code, you could have:
To Write About...
Give example of IOError, and interpreting the IOError code.
Give example of multiple excepts. Handling multiple excepts in one line.
Show how to use "else" and "finally".
Show how to continue with a "raise".