Message Boards Message Boards

0
|
2482 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Possible to cancel/prevent further execution of notebook if a test fails?

Posted 1 year ago

At the beginning of my notebook I am performing some checks. If these checks fail I want to prevent further evaluation of the notebook. I have tried Abort[] but that doesn't prevent evaluation continuing.

Or, could I have a "launcher" notebook which carries out the checks and only "launches" the main notebook if the checks pass?

POSTED BY: Paul Newton
2 Replies

Hi Paul,

Encapsulate all of the checks in a function. If a check fails then Abort[]. E.g

checkPreconditions[] := Module[{x = 1},
  If[True, Abort[]];
  x = 2]

Or use CompoundExpression

(
 x = 1;
 If[True, Abort[]];
 x = 2;
 Print@x
)
POSTED BY: Rohit Namjoshi
Posted 1 year ago

Hi Rohit

The most promising solution I have found so far is to create a "Launcher.nb" notebook where I carry out the "checkPreConditions" and only then use NotebookEvaluate("Launchee.nb") if the checks pass.

This seems to be working well and obviates the need for any checking in Launchee.nb.

POSTED BY: Paul Newton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract