Executing Notebooks - Run All Cells vs Run All Below

lei_armstrong
New Contributor II

Due to dependencies, if one of our cells errors then we want the notebook to stop executing.

We've noticed some odd behaviour when executing notebooks depending on if "Run all cells in this notebook" is selected from the header versus "Run All Below".

In the example code below I've added an extra bracket to force the python to fail and raise an exception. If I run the notebook using "Run all cells in this notebook" then the exception is correctly thrown and the rest of the cells/commands in the notebook are skipped.

However, if I use "Run All Below" then all cells are executed regardless of any exceptions or failures. We're tried using dbutils.notebook.exit but it doesn't work and subsequent cells are still run.

Is this the intended behaviour? It's frustrating when trying to rerun just part of a notebook.

Example Code:

Cmd 1

%python

try:

 spark.sql("""SELECT NOW()) AS force_error""")

except:

 print("Error running SQL")

 raise Exception("Error running SQL")

Cmd 2

SELECT NOW())

Cmd 3

SELECT NOW()