-
Notifications
You must be signed in to change notification settings - Fork 0
7. Error Handling
Barak Haim edited this page Apr 29, 2021
·
2 revisions
try:
<do something>
except <Exception_Type>:
<handle the "Exception_Type">
except <Exception_name> as <new_name>:
<handle the "Exception_Type" referenced as new_name>
except:
<handle any error>
else:
<come here if and only if no exception was raised>
finally:
<cleanup eventually>raise <exception_type>A list of python exceptions python exceptions.
About Try and Except in Python. Examples from medium.
assert <condition>, <optional error message>Raises an AssertionError when isn't met.
More about the assertion statment.
# Create a new class inheriting from Exception
class <new_exception_name>(Exception):
pass