Professional Documents
Culture Documents
IST603 - Exceptions in Python
IST603 - Exceptions in Python
Exceptions in Python
(From https://docs.python.org/3/tutorial/errors.html and other Sources)
Denis L. Nkweteyim
try:
raise NameError('Hi There')
●
Or maybe we want to do something with
except NameError: an exception and then allow it to continue
print('An exception flew by!')
raise
to bubble up to the parent function, as if it
had never been caught?
An exception flew by!
Traceback (most recent call last): ●
Use a simpler form of the raise statement to
File "/tmp/ipykernel_74442/1282197570.py", line 3, re-raise the exception
in <module>
raise NameError('Hi There')
NameError: Hi There
divide(3,0)
Sorry, You are dividing by zero
This is always executed