1
$\begingroup$

When building a Module function, I try to throw an error box when this function facing some cases. But I don't know how to output this error box with ground methods.

This picture is the Mma error bar I want to edit and output. the error bar I want to output

$\endgroup$
2
  • $\begingroup$ What does "throw" mean? $\endgroup$ Jul 2, 2021 at 19:44
  • $\begingroup$ When someone input commands with wrong grammar or etc., Mma would output an error box in red, similar as the picture. I just want Mma output error box with an exact function. For example, in Julia, one can input error("xxxxxx") to let Julia output an error box. $\endgroup$
    – swish47
    Jul 3, 2021 at 13:05

1 Answer 1

1
$\begingroup$

Using the function Message[] should help, using some permutation of:

command[args]:= If[Condition,Run Command, Message[args]]

Example Below:

l::len = "Argument `1` is to small";
l[n_] := If[n > 10, n+1, Message[l::len, n];]

If n>10, the function completes, if n<10; the function will print a red error message, and in this case not compile but adding n+1 after the semicolon will print an error and complete the function.

The :: defines symbol::tags----

It's written about here: https://reference.wolfram.com/language/workflow/SetUpErrorCheckingAndMessagesInAFunction.html

Message Documentation- https://reference.wolfram.com/language/ref/Message.html?q=Message

I highly recommend looking up the documentation, with natural language searches, the search "make error message wolfram" took me to the WL guide page. WL documentation and stack exchange have loads of already answered questions and guides similar to your needs!

Happy coding!

$\endgroup$
1
  • $\begingroup$ Thank u very much. It is exactly useful. $\endgroup$
    – swish47
    Jul 3, 2021 at 18:21

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.