Ignoring Errors¶
Normally, if an exception is raised while executing a notebook, the Sphinx build process is stopped immediately.
If a notebook contains errors on purpose (or if you are too lazy to fix them right now), you have four options:
Manually execute the notebook in question and save the results, see the pre-executed example notebook.
Allow errors in all notebooks by setting this option in conf.py:
nbsphinx_allow_errors = True
Allow errors on a per-notebook basis by adding this to the notebook’s JSON metadata:
"nbsphinx": { "allow_errors": true },
Allow errors on a per-cell basis using the
raises-exception
tag, see Ignoring Errors on a Cell-by-Cell Basis.
This very notebook is an example for the third option. The results of the following code cells are not stored within the notebook, therefore it is executed during the Sphinx build process. Since the above-mentioned allow_errors
flag is set in this notebook’s metadata, all cells are executed although most of them cause an exception.
[1]:
nonsense
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In [1], line 1
----> 1 nonsense
NameError: name 'nonsense' is not defined
[2]:
42 / 0
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
Cell In [2], line 1
----> 1 42 / 0
ZeroDivisionError: division by zero
[3]:
6 * 7
[3]:
42