Navigation

Operators and Keywords

Function List:

C++ API

: warning (template, …)
: warning (id, template, …)
: warning ("on", id)
: warning ("off", id)
: warning ("query", id)
: warning ("error", id)
: warning (state, "backtrace")
: warning (state, id, "local")

Display a warning message or control the behavior of Octave’s warning system.

Format the optional arguments under the control of the template string template using the same rules as the printf family of functions (see ‘Formatted Output’) and print the resulting message on the stderr stream. 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. A message identifier is of the form "NAMESPACE:WARNING-NAME". Octave’s own warnings use the "Octave" namespace (see ‘XREFwarning_ids’). The special identifier "all" may be used to set the state of all warnings.

If the first argument is "on" or "off", set the state of a particular warning using the identifier id. If the first argument is "query", query the state of this warning instead. 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. So, for example, the following handles all warnings as errors:

warning ("error");

If the state is "on" or "off" and the third argument is "backtrace", then a stack trace is printed along with the warning message when warnings occur inside function calls. This option is enabled by default.

If the state is "on", "off", or "error" and the third argument is "local", then the warning state will be set temporarily, until the end of the current function. Changes to warning states that are set locally affect the current function and all functions called from the current scope. The previous warning state is restored on return from the current function. The "local" option is ignored if used in the top-level workspace.

Implementation Note: For compatibility with MATLAB, escape sequences in template (e.g., "\n" => newline) are processed regardless of whether template has been defined with single quotes, as long as there are two or more input arguments. To disable escape sequence expansion use a second backslash before the sequence (e.g., "\\n") or use the regexptranslate function.

See also: warning_ids, lastwarn, error.

Package: octave