Suppose I got in a Dialog and wanted to not Return but Abort the computation. How could I do that?

Using Return[] the computation continues, and sometimes that implies getting inside countless other Dialogs of which it is not easy to go out without killing the kernel.

How do you handle those situations?


1 Answer 1


I use ExitDialog@Unevaluated@Abort[]

If your dialog is unhappily inside a CheckAbort you can go for exceptions like ExitDialog@Unevaluated@Throw["OOOUT", Unique[]] for example.

In this way, tools like TraceDialog become very useful. TraceDialog[code, Message] is something I use often, to see the Stack, the state, etc

Note that this only aborts one level. If you want 2 levels you could do ExitDialog@Unevaluated@ExitDialog@Unevaluated@Abort[]

For a general way to abort all dialogs of any level at once, one could do

  ConstantArray[Function[i, ExitDialog@Unevaluated@i, HoldFirst], 
  • $\begingroup$ Seems that ExitDialog is equivalent to Return in this case? $\endgroup$
    – xzczd
    Jan 18, 2017 at 4:53
  • $\begingroup$ @xzczd in what case? $\endgroup$
    – Rojo
    Jan 19, 2017 at 1:59
  • $\begingroup$ I mean ExitDialog@Unevaluated@Abort[] and Return@Unevaluated@Abort[] has the same effect? $\endgroup$
    – xzczd
    Jan 19, 2017 at 5:58
  • 1
    $\begingroup$ @xzczd That didn't work for me last I tried. It made the dialog return Unevaluated@Abort[] so nothing got aborted. $\endgroup$
    – Rojo
    Jan 20, 2017 at 6:08
  • $\begingroup$ @xzczd yeah. It seems Return returns even when run without [...], and the Unevaluated doesn't work as one would expect. $\endgroup$
    – Rojo
    Jan 20, 2017 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.