Python Language Exceptions: Difference between revisions
Jump to navigation
Jump to search
(→raise) |
|||
Line 14: | Line 14: | ||
To conditionally trigger an exception in the code, use <code>[[#assert|assert]]</code>. | To conditionally trigger an exception in the code, use <code>[[#assert|assert]]</code>. | ||
=<tt>try/except</tt>= | |||
=<tt>raise</tt>= | =<tt>raise</tt>= | ||
=<tt> assert </tt>= | =<tt> assert </tt>= |
Revision as of 23:26, 20 January 2022
Internal
Overview
try/except
is a language-level mechanism to handle errors (traceback) that may be caused by a section of the code. This syntax eliminates tracebacks.
try:
# do something
except:
# execute if the previous block caused an error
To trigger an exception manually in the code use raise
.
To conditionally trigger an exception in the code, use assert
.