6
$\begingroup$

Here's an example of what I mean by an "ErrorBox behavior". In the front end, if one evaluates the expression

Graphics[Circle[], ImageSize -> Tiny, PlotRange -> {All}]

(which includes the invalid option setting PlotRange -> {All}), one gets this:

enter image description here

If one then hovers the mouse over the pink ErrorBox (or clicks on the yellow + sign), one reads an appropriate error message:

The specified setting for the option GraphicsBoxOptions, PlotRange cannot be used.


Now, suppose I'm implementing some function foo.

How can I have foo trigger a similar behavior in the front end (say, in response of some invalid argument)?

(By similar behavior I mean the combination of an ErrorBox with the mouse-over behavior described above, the yellow + and red bracket, the the error message in the Messages window, etc.)

IOW, I'm looking for some built-in function, let's call it UserError, such that the expression

UserError["The specified setting for the option Frobozz is invalid."]

will result in an output featuring a pink ErrorBox, etc.

Also, what is the counterpart of the pink ErrorBox when Mathematica runs without a graphical front end? For example, just like a user can tell, from seeing a pink ErrorBox, that "something went wrong", can an unsupervised script make a similar determination?

NOTES

  1. Here, to facilitate the description of my question, I've used the low-level construct ErrorBox as a convenient visible feature of a high-level behavior (namely the response to an error). I am not interested, however, in the low-level task of creating an ErrorBox, per se (as described in the documentation for ErrorBox). Rather, I want to find out how to trigger the high-level behavior that, among other things, has an ErrorBox as one of its visible features.

  2. Neither Message, Abort, nor Throw trigger the behavior described above.

$\endgroup$
  • $\begingroup$ It is not clear to me what exactly you are asking. Could you please make a specific foo example with an invalid input and describe exactly what you would like to obtain from MMA? $\endgroup$ – magma Mar 26 '17 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.