Lecture 12: November 7, 2019
Reading
: §3.7, 7.7
Due
: Homework 3, due on November 8 at 11:59pm
Common exceptions
ZeroDivisionError
— attempt to divide (or take the remainder of) something by 0
TypeError
— operation or function applied to operand of wrong type
SyntaxError
— Python parser encountered a malformed statement
NameError
— local or global name is not found
ValueError
— built-in function or operation applied to operator with illegal value
EOFError
— input function encounters an end of file
Keyboard Interrupt
— user hit the interrupt key (usually control-C)
Handling exceptions
except
[
except0.py
]
except
exceptcode
[
except1.py
]
else
[
except2.py
]
except
exceptcode
as
msgvar
[
except3.py
]
finally
[
except4.py
]
Exceptions in a function: who handles them? [
except5.py
[
except6.py
]
Using global variables as error flags [
except6a.py
]
raise
exceptcode
message
[
except7.py
]
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email:
[email protected]
MHI 289I, Programming in Health Informatics
Version of November 11, 2019 at 10:10AM
You can also obtain a PDF version of this.