Outline for February 20, 2019
Due
: Homework 3, due February 22, 2019
— note extension
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
RecursionError
— recursive function recursed too deeply
KeyError
— key does not exist in dictionary
IndexError
— no item with that index in list
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
]
Online Python documentation
JSON [
jsoon-ex.py
]
What it is
json.loads
json.dumps
Matt Bishop
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562 USA
Last modified: Version of February 13, 2019 at 8:37PM
Winter Quarter 2019
You can get a PDF version of this