|GNU Octave Manual Version 3|
by John W. Eaton, David Bateman, Søren Hauberg
Paperback (6"x9"), 568 pages
RRP £24.95 ($39.95)
12.2.1 Issuing Warnings
It is possible to issue warnings from any code using the
function. In its most simple form, the
warning function takes a
string describing the warning as its input argument. As an example,
the following code controls if the variable ‘a’ is non-negative,
and if not issues a warning and sets ‘a’ to zero.
a = -1; if (a < 0) warning ("'a' must be non-negative. Setting 'a' to zero."); a = 0; endif -| 'a' must be non-negative. Setting 'a' to zero.
Since warnings aren't fatal to a running program, it is not possible
to catch a warning using the
try statement or something similar.
It is however possible to access the last warning as a string using the
It is also possible to assign an identification string to a warning.
If a warning has such an ID the user can enable and disable this warning
as will be described in the next section. To assign an ID to a warning,
warning with two string arguments, where the first
is the identification string, and the second is the actual warning.
- Built-in Function: warning (template, ...)
- Built-in Function: warning (id, template, ...)
- Format the optional arguments under the control of the template string
template using the same rules as the
printffamily of functions (see section 14.2.4 Formatted Output) and print the resulting message on the
stderrstream. The message is prefixed by the character string ‘warning: ’. You should use this function when you want to notify the user of an unusual condition, but only when it makes sense for your program to go on.
The optional message identifier allows users to enable or disable warnings tagged by id. The special identifier ‘"all"’ may be used to set the state of all warnings.
- Built-in Function: warning ("on", id)
- Built-in Function: warning ("off", id)
- Built-in Function: warning ("error", id)
- Built-in Function: warning ("query", id)
- Set or query the state of a particular warning using the identifier
id. If the identifier is omitted, a value of ‘"all"’ is
assumed. If you set the state of a warning to ‘"error"’, the
warning named by id is handled as if it were an error instead.
See also warning_ids
- Built-in Function: [msg, msgid] = lastwarn (msg, msgid)
- Without any arguments, return the last warning message. With one argument, set the last warning message to msg. With two arguments, also set the last message identifier.
|ISBN 095461206X||GNU Octave Manual Version 3||See the print edition|