Error and Warning Message Formatting
Description
The % Parameter Options
Special Parameter %0
Examples
Errors generated by Maple statements using the error keyword, warnings displayed by the WARNING function, and error- or warning-like strings produced by the StringTools:-FormatMessage function, all display or produce a result based on the same formatting rules.
The error keyword throws and prints an exception message. Calling the WARNING function prints a warning message. FormatMessages does not throw an exception or print, but returns a string containing the message.
For each of these operations, there are ...
If error, WARNING, or FormatMessage has a single argument, that argument is raised, displayed, or returned as the message. If the argument is not a string, it is converted to one.
If there are multiple arguments, and the first argument does not contain %-parameter formatting options as described below, or is not a string or name, there is again a single message produced, consisting of the multiple arguments concatenated by one or more ", " (a comma and space). Any argument that is not a string is converted to one during concatenation.
If the first argument is a string or name that does contain %-parameters, then the remaining arguments are treated as values to be substituted for them. If there are too few such additional arguments, such %-parameters are left unsubstituted. If there are too many such arguments, they are simply ignored.
The userinfo procedure can also use %-parameter output. Unlike the three forms above, userinfo accepts two additional arguments before the message itself. It will expect the %-parameters to appear in its third argument specified as a string (not a name), with any parameters in the fourth and further arguments.
Each individual % option controls how an additional value passed to an error, warning, or message is to be formatted.
Each % option is completed by a number specifying which additional argument is to be formatted as part of the resulting message. Because these parameters are numbered, they can be formatted more than once, or in a different order than they are passed, if desired.
The default form, %n, where n is generally an integer between 1 and the number of additional arguments, formats the nth additional argument in one-dimensional Maple syntax, with one significant exception:
If the value to be formatted is a string or name, quotation marks will not be shown even if they would normally be required for Maple input of such values. This is for historical reasons, as such parameters might be desired to represent plain text, not actual expressions.
The output produced by the form, %+n, is equivalent to the %n form, except that any necessary string or name quotes are produced.
Note that simple names that do not require quotes for input are not produced with quotes for output either. If one wants to produce an error or warning messages where such name quotes always appear, use the regular %n option, with name quotes in the message text itself.
A numbered parameter of the form %-n formats the value of the nth argument in ordinal form. If the value is zero or a positive integer, the ordinal is produced in a straightforward form. For example, the value 2 would be formatted as "2nd", and 117 as "117th".
If the value is not an integer, or is a negative integer, the suffix used after the value is "-th". For example, the values y and -4 would format as "y-th" and "-4-th" respectively.
Instead of formatting a number directly or in ordinal form, its value can be used to select one of three specified character sequences. This is specified by the form %{n|c0|c1|c2}. If the value passed for parameter n has the value 0, then the specified c0 is produced. If the value equals 1, c1 is produced. If the value is not 0 or 1, then the c2 value is produced.
Instead of referring to an nth argument, the form %0 or %+0 refers to all the arguments of an error or warning.
If there is a single argument, it is displayed as it would be for a corresponding %n or %+n. If there are multiple arguments, they are all displayed, each separated by a comma and space.
Like %+n, the output produced for each argument of %+0 is equivalent to that of %0, except that any necessary string or name quotes are produced.
Errors interrupt computation, warnings simply display a message, and FormatMessage returns a message as a string. Any without % are simply appended by commas if there's more than one.
errorfirst part,second part
Error, first part, second part
WARNING⁡first part,second part
Warning, first part, second part
StringTools:-FormatMessage⁡first part,second part
first part, second part
The remaining examples all use the error command, but the same result forms are supported by WARNING (as output) and FormatMessage (as a returned string).
Since parameters are numbered, they can be displayed in a different order or more than once.
errorsecond is %2, first was %1,number one,the second
Error, second is the second, first was number one
error%1 and %1 are the same thing,the first
Error, the first and the first are the same thing
Parameters are substituted. If there are too few or too many, they are displayed unsubstituted or ignored respectively.
errorpart %1 and part %2,one,TWO
Error, part one and part TWO
errorpart %1 and part %2,only one
Error, part only one and part %2
errorpart %1 and part %2,one,TWO,`where is 3`
The % and %+ forms are equivalent, except that the former omits quotation of top-level string or name expressions.
errorparts %1, %2, and %3,string,simpleName,`complex name`
Error, parts string, simpleName, and complex name
errorparts %+1, %+2, and %+3,string,simpleName,`complex name`
Error, parts "string", simpleName, and `complex name`
erroralways quoted `%1` and `%2`,simpleName,`complex name`
Error, always quoted `simpleName` and `complex name`
The %- form is used to produce ordinal output.
errorthe %-1, %-2, and %-3 parts,4,222,N
Error, the 4th, 222nd, and N-th parts
The %{...} format is used to produce output depending on a parameter equaling 0, 1, or some other quantity.
error%1 %{1|isn't any|is one|are many},0
Error, 0 isn't any
error%1 %{1|isn't any|is one|are many},1
Error, 1 is one
error%1 %{1|isn't any|is one|are many},123
Error, 123 are many
The %0 and %+0 formats are applied to all parameters instead of just a specified individual.
errorarguments %0,string,simpleName,`complex Name`,3.14
Error, arguments string, simpleName, complex Name, 3.14
errorarguments %+0,string,simpleName,`complex Name`,3.14
Error, arguments "string", simpleName, `complex Name`, 3.14
The userinfo procedure also supports all %, %+, %-, and %{...} forms.
f := proc(x,y) userinfo(3,f,"values %1 and %2",x,y); x*y end;
f ≔ procx,yuserinfo⁡3,f,values %1 and %2,x,y;y*xend proc
infolevelf≔3
f⁡4,sin⁡x
f: "values 4 and sin(x)"
4⁢sin⁡x
See Also
error
StringTools:-FormatMessage
userinfo
WARNING
Download Help Document