|
114 | 114 | \listingPython{exceptions:sqrt_raise}{%
|
115 | 115 | A new variant of the \pythonil{sqrt} function from back in \cref{lst:functions:my_math_2} that raises an \pythonilIdx{ArithmeticError} if its input is non-finite or negative.}%
|
116 | 116 | %
|
117 |
| -\gitPythonAndErrorOutput{\programmingWithPythonCodeRepo}{exceptions}{use_sqrt_raise.py}{--args format}{exceptions:use_sqrt_raise}{% |
| 117 | +\gitLoadAndExecPythonAndErrors{exceptions:use_sqrt_raise}{}{exceptions}{use_sqrt_raise.py}{}% |
| 118 | +\listingPythonAndError{exceptions:use_sqrt_raise}{use_sqrt_raise.py}{% |
118 | 119 | Using the new variant of the \pythonil{sqrt} function from \cref{lst:exceptions:sqrt_raise} that raises an \pythonilIdx{ArithmeticError} if its input is non-finite or negative.}%
|
119 | 120 | %
|
120 | 121 | Let us now first look at an example of how we can signal an error condition in our code.
|
|
298 | 299 | The \pythonilIdx{except} block is not to be used to just catch any exception, to implement \gls{GIGO}, or to try to sanitize erroneous input.%
|
299 | 300 | }%
|
300 | 301 | %
|
301 |
| -\gitPythonAndErrorOutput{\programmingWithPythonCodeRepo}{exceptions}{try_multi_except.py}{--args format}{exceptions:try_multi_except}{% |
| 302 | +\gitLoadAndExecPythonAndErrors{exceptions:try_multi_except}{}{exceptions}{try_multi_except.py}{}% |
| 303 | +\listingPythonAndError{exceptions:try_multi_except}{try_multi_except.py}{% |
302 | 304 | The handling of multiple errors, namely \pythonilIdx{ZeroDivisionError} and \pythonilIdx{ArithmeticError}, as well as what happens if a variable remains unassigned due to an error (a \pythonilIdx{NameError} is raised).}%
|
303 | 305 | %
|
304 | 306 | In \cref{lst:exceptions:try_multi_except}, we revisit our new \pythonil{sqrt} function.
|
|
341 | 343 | %
|
342 | 344 | \hsection{Exceptions in Exception Handlers}%
|
343 | 345 | %
|
344 |
| -\gitPythonAndErrorOutput{\programmingWithPythonCodeRepo}{exceptions}{try_except_nested_1.py}{--args format}{exceptions:try_except_nested_1}{% |
| 346 | +\gitLoadAndExecPythonAndErrors{exceptions:try_except_nested_1}{}{exceptions}{try_except_nested_1.py}{}% |
| 347 | +\listingPythonAndError{exceptions:try_except_nested_1}{try_except_nested_1.py}{% |
345 | 348 | An example of \pythonils{Exception} being raised inside an \pythonilIdx{except} block.}%
|
346 | 349 | %
|
347 | 350 | What happens if an exception is raised \emph{inside} an \pythonilIdx{except} block?
|
|
445 | 448 | next statement # Executed only if there are no uncaught Exceptions.
|
446 | 449 | \end{pythonSyntax}
|
447 | 450 | %
|
448 |
| -\gitPythonAndErrorOutput{\programmingWithPythonCodeRepo}{exceptions}{try_except_else_finally.py}{--args format}{exceptions:try_except_else_finally}{% |
| 451 | +\gitLoadAndExecPythonAndErrors{exceptions:try_except_else_finally}{}{exceptions}{try_except_else_finally.py}{}% |
| 452 | +\listingPythonAndError{exceptions:try_except_else_finally}{try_except_else_finally.py}{% |
449 | 453 | An example for the \pythonilIdx{try}-\pythonilIdx{except}-\pythonilIdx{else}-\pythonilIdx{finally} block.}%
|
450 | 454 | %
|
451 | 455 | \gitExec{exec:exceptions:try_except_else_finally:mypy}{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh exceptions try_except_else_finally.py}%
|
|
0 commit comments