875
Comment: To do: Write about how to capture catch-all "Exception"
|
989
Catch-all is bad, but how to do it anyways. (to-do.)
|
Deletions are marked like this. | Additions are marked like this. |
Line 30: | Line 30: |
Give example of multiple excepts. Handling multiple excepts in one line. Catch-all "Exception" exception handling. | Give example of multiple excepts. Handling multiple excepts in one line. Catch-all "Exception" exception handling. (Note: JohannesGijsbers says this is ''bad.'' We should have a note about why it's bad, next to how to do it.) |
Handling Exceptions
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.
Catch-all "Exception" exception handling. (Note: JohannesGijsbers says this is bad. We should have a note about why it's bad, next to how to do it.)
Show how to use "else" and "finally".
Show how to continue with a "raise".
See Also:
WritingExceptionClasses, TracebackModule, CoupleLeapingWithLooking