.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_auto_examples_no_output_plot_raise.py>`     to download the full example code or to run this example in your browser via Binder
    .. rst-class:: sphx-glr-example-title

    .. _sphx_glr_auto_examples_no_output_plot_raise.py:


Example that fails to execute
=============================

This example demonstrates a code block that raises an error and how any code
blocks that follow are not executed.

When scripts fail, their gallery thumbnail is replaced with the broken
image stamp. This allows easy identification in the gallery display.

You will also get the python traceback of the failed code block.


.. code-block:: python3
   :lineno-start: 15


    # Code source: Óscar Nájera
    # License: BSD 3 clause
    # sphinx_gallery_line_numbers = True

    import numpy as np
    import matplotlib.pyplot as plt

    plt.pcolormesh(np.random.randn(100, 100))




.. image:: /auto_examples/no_output/images/sphx_glr_plot_raise_001.png
    :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none


    <matplotlib.collections.QuadMesh object at 0x7f3bfbfb3e20>



This next block will raise a NameError


.. code-block:: python3
   :lineno-start: 27


    iae



.. rst-class:: sphx-glr-script-out


.. code-block:: pytb

    Traceback (most recent call last):
      File "/build/sphinx-gallery-742mVY/sphinx-gallery-0.6.2/.pybuild/cpython3_3.8_sphinx-gallery/build/sphinx_gallery/gen_rst.py", line 453, in _memory_usage
        mem, out = memory_usage(func, max_usage=True, retval=True,
      File "/usr/lib/python3/dist-packages/memory_profiler.py", line 333, in memory_usage
        returned = f(*args, **kw)
      File "/build/sphinx-gallery-742mVY/sphinx-gallery-0.6.2/.pybuild/cpython3_3.8_sphinx-gallery/build/sphinx_gallery/gen_rst.py", line 442, in __call__
        exec(self.code, self.fake_main.__dict__)
      File "/build/sphinx-gallery-742mVY/sphinx-gallery-0.6.2/examples/no_output/plot_raise.py", line 27, in <module>
        iae
    NameError: name 'iae' is not defined




Sphinx gallery will stop executing the remaining code blocks after
the exception has occurred in the example script. Nevertheless the
html will still render all the example annotated text and
code blocks, but no output will be shown.

Here is another error raising block but will not be executed


.. code-block:: python3
   :lineno-start: 38


    plt.plot('Strings are not a valid argument for the plot function')

**Estimated memory usage:**  193 MB


.. _sphx_glr_download_auto_examples_no_output_plot_raise.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example


  .. container:: binder-badge

    .. image:: https://mybinder.org/badge_logo.svg
      :target: https://mybinder.org/v2/gh/sphinx-gallery/sphinx-gallery.github.io/master?urlpath=lab/tree/notebooks/auto_examples/no_output/plot_raise.ipynb
      :width: 150 px


  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: plot_raise.py <plot_raise.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: plot_raise.ipynb <plot_raise.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
