I would like a notebook evaluation to entirely stop when an Assert
fails, without quitting the kernel. Is this possible (e.g., by setting $AssertFunction
to ... something)?
Edit:
For example, if I create a notebook containing a cell with the following lines, I would like the value of test
to still be 0
, and for no subsequent cells to be exectuted.
test = 0;
Assert[False];
test = 1;
An additionalEDIT:
Note that setting $AssertFunction=Abort[]&
does not work, because it only aborts the current computation, but afterwards evaluation continues to proceed through the notebook.
A related question: why must we execute On[Assert]
before we can set $AssertFunction
? Naturally I understand why we must turn assertions on and off; that is not my question. My question is why On[Assert]
apparently resets $AssertFunction
:
On[Assert]
$AssertFunction = Abort[] &;
Assert[False] (* aborts *)
Off[Assert]
On[Assert]
Assert[False] (* does not abort *)