Errors and Warnings
*******************

Octave includes several functions for printing error and warning messages.  When you write functions that need to take special action when they encounter abnormal conditions, you should print the error messages using the functions described in this chapter.

Since many of Octave's functions use these functions, it is also useful to understand them, so that errors and warnings can be handled.

Handling Errors
===============

An error is something that occurs when a program is in a state where it doesn't make sense to continue.  An example is when a function is called with too few input arguments.  In this situation the function should abort with an error message informing the user of the lacking input arguments.

Since an error can occur during the evaluation of a program, it is very convenient to be able to detect that an error occurred, so that the error can be fixed.  This is possible with the try statement described in The try Statement.

Raising Errors
--------------

The most common use of errors is for checking input arguments to functions.  The following example calls the error function if the function f is called without any input arguments.

     function f (arg1)
       if (nargin == 0)
         error ("not enough input arguments");
       endif
     endfunction

When the error function is called, it prints the given message and returns to the Octave prompt.  This means that no code following a call to error will be executed.

It is also possible to assign an identification string to an error. If an error has such an ID the user can catch this error as will be described in the next section.  To assign an ID to an error, simply call error with two string arguments, where the first is the identification string, and the second is the actual error.  Note that error IDs are in the format "NAMESPACE:ERROR-NAME".  The namespace "Octave" is used for Octave's own errors.  Any other string is available as a namespace for user's own errors.

 -- error: (MSG)
 -- error: (TEMPLATE, ...)
 -- error: (ID, TEMPLATE, ...)
 -- error: (ERRSTRUCT)
     Display an error message and stop m-file execution.

     The input MSG is a simple string to which the text error:  is prepended.  The resulting message is printed on the stderr stream. Alternatively, the first input may be a template string TEMPLATE which uses the same rules as the printf family of functions (see Formatted Output).  Formatting is only done for single-quoted character vectors if there are additional arguments following the template string.  If there are no additional arguments, the template string is used literally (i.e., without interpreting any escape sequences in single-quoted character vectors).

     The optional ID argument allows programmers to tag an error with a specific identifier so that users can later retrieve it (using lasterr or lasterror) and know the origin of the error. The identifier must contain at least one colon character (':') and must not contain any whitespace characters.  It should be a string of the form "NAMESPACE:ERROR-NAME".  Octave's own errors use the "Octave" namespace (see error_ids). For example:

          error ("MyNameSpace:wrong-type-argument",
                 "fcn_name: argument should be numeric");

     Calling error also sets Octave's internal error state such that control will return to the top level without evaluating any further commands.  This is useful for aborting from functions or scripts.

     If the error message does not end with a newline character, Octave will print a traceback of all the function calls leading to the error.  For example, given the following function definitions:

          function f () g (); end
          function g () h (); end
          function h () nargin == 1 || error ("nargin != 1"); end

     calling the function f will result in a list of messages that can help you to quickly find the exact location of the error:

          f ()
          error: nargin != 1
          error: called from:
          error:   h at line 1, column 27
          error:   g at line 1, column 15
          error:   f at line 1, column 15

     If the error message ends in a newline character, Octave will print the message but will not display any traceback messages as it returns control to the top level.  For example, modifying the error message in the previous example to end in a newline causes Octave to only print a single message:

          function h () nargin == 1 || error ("nargin != 1\n"); end
          f ()
          error: nargin != 1

     A null string ("") input to error will be ignored and the code will continue running as if the statement were a NOP.  This is for compatibility with MATLAB.  It also makes it possible to write code such as

          err_msg = "";
          if (CONDITION 1)
            err_msg = "CONDITION 1 found";
          elseif (CONDITION2)
            err_msg = "CONDITION 2 found";
          ...
          endif
          error (err_msg);

     which will only stop execution if an error has been found.

     The function may also be called with an error structure such as that returned from lasterror.  The ERRSTRUCT argument must contain fields message, identifier, and stack.  The first two fields are strings with the meanings discussed above.  The stack field must be a structure or structure array with fields file, name, and line.

     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. warning, lasterror

Since it is common to use errors when there is something wrong with the input to a function, Octave supports functions to simplify such code. When the print_usage function is called, it reads the help text of the function calling print_usage, and presents a useful error. If the help text is written in Texinfo it is possible to present an error message that only contains the function prototypes as described by the @deftypefn parts of the help text.  When the help text isn't written in Texinfo, the error message contains the entire help message.

Consider the following function.

     ## -*- texinfo -*-
     ## @deftypefn {} f (@var{arg1})
     ## Function help text goes here...
     ## @end deftypefn
     function f (arg1)
       if (nargin == 0)
         print_usage ();
       endif
     endfunction

When it is called with no input arguments it produces the following error.

     f ()

     -|  error: Invalid call to f.  Correct usage is:
     -|
     -|   -- f (ARG1)
     -|
     -|
     -|  Additional help for built-in functions and operators is
     -|  available in the online version of the manual.  Use the command
     -|  'doc <topic>' to search the manual index.
     -|
     -|  Help and information about Octave is also available on the WWW
     -|  at https://www.octave.org and via the help@octave.org
     -|  mailing list.

 -- print_usage: ()
 -- print_usage: (NAME)
     Print the usage message for the function NAME.

     When called with no input arguments the print_usage function displays the usage message of the currently executing function. help

 -- beep: ()
     Produce a beep from the speaker (or visual bell).

     This function sends the alarm character "\a" to the terminal.  Depending on the user's configuration this may produce an audible beep, a visual bell, or nothing at all. puts, fputs, printf, fprintf

 -- VAL =: beep_on_error ()
 -- OLD_VAL =: beep_on_error (NEW_VAL)
 -- OLD_VAL =: beep_on_error (NEW_VAL, "local")
     Query or set the internal variable that controls whether Octave will try to ring the terminal bell before printing an error message.

     When called from inside a function with the "local" option, the variable is changed locally for the function and any subroutines it calls. The original variable value is restored when exiting the function.

Catching Errors
---------------

When an error occurs, it can be detected and handled using the try statement as described in The try Statement. As an example, the following piece of code counts the number of errors that occurs during a for loop.

     number_of_errors = 0;
     for n = 1:100
       try
         ...
       catch
         number_of_errors++;
       end_try_catch
     endfor

The above example treats all errors the same.  In many situations it can however be necessary to discriminate between errors, and take different actions depending on the error.  The lasterror function returns a structure containing information about the last error that occurred.  As an example, the code above could be changed to count the number of errors related to the * operator.

     number_of_errors = 0;
     for n = 1:100
       try
         ...
       catch
         msg = lasterror.message;
         if (strfind (msg, "operator *"))
           number_of_errors++;
         endif
       end_try_catch
     endfor

Alternatively, the output of the lasterror function can be found in a variable indicated immediately after the catch keyword, as in the example below showing how to redirect an error as a warning:

     try
       ...
     catch err
       warning(err.identifier, err.message);
       ...
     end_try_catch

 -- LASTERR =: lasterror ()
 -- lasterror: (ERR)
 -- lasterror: ("reset")
     Query or set the last error message structure.

     When called without arguments, return a structure containing the last error message and other information related to this error.  The elements of the structure are:

     message
          The text of the last error message

     identifier
          The message identifier of this error message

     stack
          A structure containing information on where the message occurred.  This may be an empty structure if the information cannot be obtained.  The fields of the structure are:

          file
               The name of the file where the error occurred

          name
               The name of function in which the error occurred

          line
               The line number at which the error occurred

          column
               An optional field with the column number at which the error occurred

     The last error structure may be set by passing a scalar structure, ERR, as input.  Any fields of ERR that match those above are set while any unspecified fields are initialized with default values.

     If lasterror is called with the argument "reset", all fields are set to their default values. lasterr, error, lastwarn

 -- [MSG, MSGID] =: lasterr ()
 -- lasterr: (MSG)
 -- lasterr: (MSG, MSGID)
     Query or set the last error message.

     When called without input arguments, return the last error message and message identifier.

     With one argument, set the last error message to MSG.

     With two arguments, also set the last message identifier. lasterror, error, lastwarn

The next example counts indexing errors.  The errors are caught using the field identifier of the structure returned by the function lasterror.

     number_of_errors = 0;
     for n = 1:100
       try
         ...
       catch
         id = lasterror.identifier;
         if (strcmp (id, "Octave:invalid-indexing"))
           number_of_errors++;
         endif
       end_try_catch
     endfor

The functions distributed with Octave can issue one of the following errors.

Octave:bad-alloc
     Indicates that memory couldn't be allocated.

Octave:invalid-context
     Indicates the error was generated by an operation that cannot be executed in the scope from which it was called.  For example, the function print_usage () when called from the Octave prompt raises this error.

Octave:invalid-fun-call
     Indicates that a function was called in an incorrect way, e.g., wrong number of input arguments.

Octave:invalid-indexing
     Indicates that a data-type was indexed incorrectly, e.g., real-value index for arrays, nonexistent field of a structure.

Octave:invalid-input-arg
     Indicates that a function was called with invalid input arguments.

Octave:parse-error
     The interpreter failed to parse (read) specified code.

Octave:undefined-function
     Indicates a call to a function that is not defined.  The function may exist but Octave is unable to find it in the search path.

When an error has been handled it is possible to raise it again.  This can be useful when an error needs to be detected, but the program should still abort.  This is possible using the rethrow function.  The previous example can now be changed to count the number of errors related to the * operator, but still abort if another kind of error occurs.

     number_of_errors = 0;
     for n = 1:100
       try
         ...
       catch
         msg = lasterror.message;
         if (strfind (msg, "operator *"))
           number_of_errors++;
         else
           rethrow (lasterror);
         endif
       end_try_catch
     endfor

 -- rethrow: (ERR)
     Reissue a previous error as defined by ERR.

     ERR is a structure that must contain at least the "message" and "identifier" fields.  ERR can also contain a field "stack" that gives information on the assumed location of the error.  Typically ERR is returned from lasterror. lasterror, lasterr, error

 -- ERR =: errno ()
 -- ERR =: errno (VAL)
 -- ERR =: errno (NAME)
     Query or set the system-dependent variable errno.

     When called with no inputs, return the current value of errno.

     When called with a numeric input VAL, set the current value of errno to the specified value.  The previous value of errno is returned as ERR.

     When called with a character string NAME, return the numeric value of errno which corresponds to the specified error code.  If NAME is not a recognized error code then -1 is returned.

     errno_list

 -- S =: errno_list ()
     Return a structure containing the system-dependent errno values. errno

Recovering From Errors
----------------------

Octave provides several ways of recovering from errors.  There are try/catch blocks, unwind_protect/unwind_protect_cleanup blocks, and finally the onCleanup command.

The onCleanup command associates an ordinary Octave variable (the trigger) with an arbitrary function (the action).  Whenever the Octave variable ceases to exist---whether due to a function return, an error, or simply because the variable has been removed with clear---then the assigned function is executed.

The function can do anything necessary for cleanup such as closing open file handles, printing an error message, or restoring global variables to their initial values.  The last example is a very convenient idiom for Octave code. For example:

     function rand42
       old_state = rand ("state");
       restore_state = onCleanup (@() rand ("state", old_state));
       rand ("state", 42);
       ...
     endfunction  # rand generator state restored by onCleanup

 -- OBJ =: onCleanup (FUNCTION)
     Create a special object that executes a given FUNCTION upon destruction.

     If the object is copied to multiple variables (or cell or struct array elements) or returned from a function, then FUNCTION will be executed only after the last copy of the object is cleared.

     The input FUNCTION is a handle to a function.  The handle may point to an anonymous function in order to directly place commands in the onCleanup call.

     Programming Note: If multiple local onCleanup variables are created, the order in which they are called is unspecified.  For similar functionality see The unwind_protect Statement.

     Example

          octave:1> trigger = onCleanup (@() disp ('onCleanup was executed'));
          octave:2> clear trigger
          onCleanup was executed
          octave:3

Handling Warnings
=================

Like an error, a warning is issued when something unexpected happens. Unlike an error, a warning doesn't abort the currently running program. A simple example of a warning is when a number is divided by zero.  In this case Octave will issue a warning and assign the value Inf to the result.

     a = 1/0
          -| warning: division by zero
          => a = Inf

Issuing Warnings
----------------

It is possible to issue warnings from any code using the warning 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 lastwarn function.

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, simply call warning with two string arguments, where the first is the identification string, and the second is the actual warning.  Note that warning IDs are in the format "NAMESPACE:WARNING-NAME".  The namespace "Octave" is used for Octave's own warnings.  Any other string is available as a namespace for user's own warnings.

 -- warning: (TEMPLATE, ...)
 -- warning: (ID, TEMPLATE, ...)
 -- warning: ("on", ID)
 -- warning: ("off", ID)
 -- warning: ("error", ID)
 -- warning: ("query", ID)
 -- warning: (STATE, ID, "local")
 -- warning: (WARNING_STRUCT)
 -- WARNING_STRUCT =: warning (...)
 -- warning: (STATE, MODE)

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

     The first call form uses a template TEMPLATE and optional additional arguments to display a message on the stderr stream.  The message is formatted using the same rules as the printf family of functions (see Formatted Output) and 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.  For example:

          warning ("foo: maybe something wrong here");

     If the warning message does not end with a newline character, Octave will print a traceback of all the function calls leading to the warning.  If the warning message does end in a newline character, Octave will suppress the traceback messages as it returns control to the top level.  For more details and examples, see error.

     The optional warning identifier ID allows users to enable or disable warnings tagged by this identifier.  A message identifier is a string of the form "NAMESPACE:WARNING-NAME".  Octave's own warnings use the "Octave" namespace (see warning_ids).  For example:

          warning ("MyNameSpace:check-something",
                   "foo: maybe something wrong here");

     The second call form is meant to change and/or query the state of warnings. The first input argument must be a string STATE ("on", "off", "error", or "query") followed by an optional warning identifier ID or "all" (default).

     The optional output argument WARNING_STRUCT is a structure or structure array with fields "state" and "identifier".  The STATE argument may have the following values:

     "on"|"off":
          Enable or disable the display of warnings identified by ID and optionally return their previous state STOUT.

     "error":
          Turn warnings identified by ID into errors and optionally return their previous state STOUT.

     "query":
          Return the current state of warnings identified by ID.

     A structure or structure array WARNING_STRUCT, with fields "state" and "identifier", may be given as an input to achieve equivalent results.  The following example shows how to temporarily disable a warning and then restore its original state:

          loglog (-1:10);
          ## Disable the previous warning and save its original state
          [~, id] = lastwarn ();
          warnstate = warning ("off", id);
          loglog (-1:10);
          ## Restore its original state
          warning (warnstate);

     If a final argument "local" is provided 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.

     With no input argument warning () is equivalent to warning ("query", "all") except that in the absence of an output argument, the state of warnings is displayed on stderr.

     The level of verbosity of the warning system may also be controlled by two modes MODE:

     "backtrace":
          enable/disable the display of the stack trace after the warning message

     "verbose":
          enable/disable the display of additional information after the warning message

     In this case the STATE argument may only be "on" or "off".

     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. warning_ids, lastwarn, error

 -- [MSG, MSGID] =: lastwarn ()
 -- lastwarn: (MSG)
 -- lastwarn: (MSG, MSGID)
     Query or set the last warning message.

     When called without input arguments, return the last warning message and message identifier.

     With one argument, set the last warning message to MSG.

     With two arguments, also set the last message identifier to MSGID. warning, lasterror, lasterr

The functions distributed with Octave can issue one of the following warnings.

Octave:abbreviated-property-match
     If the Octave:abbreviated-property-match warning is enabled, a warning is printed if a non-exact or ambiguous match is being used for a operation specifying an object property.  For example, for a graphics object, FIG, with the property 'displayname', get (FIG, 'dis') elicits a warning if the Octave:abbreviated-property-match warning is enabled. By default, the Octave:abbreviated-property-match warning is enabled.

Octave:addpath-pkg
     If the Octave:addpath-pkg warning is enabled, Octave will warn when a package directory (i.e., +package_name) is added to the path.  Typically, only the parent directory which contains the package directory should be added to the load path. By default, the Octave:addpath-pkg warning is enabled.

Octave:array-as-logical
     If the Octave:array-as-logical warning is enabled, Octave will warn when an array of size greater than 1x1 is used as a truth value in an if, while, or until statement. By default, the Octave:array-as-logical warning is disabled.

Octave:array-to-scalar
     If the Octave:array-to-scalar warning is enabled, Octave will warn when an implicit conversion from an array to a scalar value is attempted. By default, the Octave:array-to-scalar warning is disabled.

Octave:array-to-vector
     If the Octave:array-to-vector warning is enabled, Octave will warn when an implicit conversion from an array to a vector value is attempted. By default, the Octave:array-to-vector warning is disabled.

Octave:assign-as-truth-value
     If the Octave:assign-as-truth-value warning is enabled, a warning is issued for statements like

          if (s = t)
            ...

     since such statements are not common, and it is likely that the intent was to write

          if (s == t)
            ...

     instead.

     There are times when it is useful to write code that contains assignments within the condition of a while or if statement.  For example, statements like

          while (c = getc ())
            ...

     are common in C programming.

     It is possible to avoid all warnings about such statements by disabling the Octave:assign-as-truth-value warning, but that may also let real errors like

          if (x = 1)  # intended to test (x == 1)!
            ...

     slip by.

     In such cases, it is possible suppress errors for specific statements by writing them with an extra set of parentheses.  For example, writing the previous example as

          while ((c = getc ()))
            ...

     will prevent the warning from being printed for this statement, while allowing Octave to warn about other assignments used in conditional contexts.

     By default, the Octave:assign-as-truth-value warning is enabled.

Octave:autoload-relative-file-name
     If the Octave:autoload-relative-file-name is enabled, Octave will warn when parsing autoload() function calls with relative paths to function files.  This usually happens when using autoload() calls in PKG_ADD files, when the PKG_ADD file is not in the same directory as the .oct file referred to by the autoload() command. By default, the Octave:autoload-relative-file-name warning is enabled.

Octave:charmat-truncated
     If the Octave:charmat-truncated warning is enabled, a warning is printed when a character matrix with multiple rows is converted to a string. In this case, the Octave interpreter keeps only the first row and discards the others. By default, the Octave:charmat-truncated warning is enabled.

Octave:classdef-to-struct
     If the Octave:classdef-to-struct warning is enabled, a warning is issued when a classdef object is forcibly converted into a struct with struct (CLASSDEF_OBJ).  Conversion removes the access restrictions from the object and makes private and protected properties visible. By default, the Octave:classdef-to-struct warning is enabled.

Octave:colon-complex-argument
     If the Octave:colon-complex-argument warning is enabled, a warning is issued when one of the three arguments to the colon operator (base, increment, limit) is a complex value.  For example, 1:3*i will cause a warning to be emitted. By default, the Octave:colon-complex-argument warning is enabled.

Octave:colon-nonscalar-argument
     If the Octave:colon-nonscalar-argument warning is enabled, a warning is issued when one of the three arguments to the colon operator (base, increment, limit) is not a scalar.  For example, 1:[3, 5] will cause a warning to be emitted. By default, the Octave:colon-nonscalar-argument warning is enabled.

Octave:data-file-in-path
     If the Octave:data-file-in-path warning is enabled, a warning is issued when Octave does not find the target of a file operation such as load or fopen directly, but is able to locate the file in Octave's search path for files.  The warning could indicate that a different file target than the programmer intended is being used. By default, the Octave:data-file-in-path warning is enabled.

Octave:datevec:date-format-spec
     If the Octave:datevec:date-format-spec warning is enabled, a warning is printed if the date format specification contains questionable date or time specifiers.  Typical bad patterns are using uppercase date specifiers or lowercase time specifiers. By default, the Octave:datevec:date-format-spec warning is enabled.

Octave:deprecated-function
     If the Octave:deprecated-function warning is enabled, a warning is issued when Octave encounters a function that is obsolete and scheduled for removal from Octave. By default, the Octave:deprecated-function warning is enabled.

Octave:deprecated-keyword
     If the Octave:deprecated-keyword warning is enabled, a warning is issued when Octave encounters a keyword that is obsolete and scheduled for removal from Octave. By default, the Octave:deprecated-keyword warning is enabled.

Octave:deprecated-option
     If the Octave:deprecated-option warning is enabled, a warning is issued when an obsolete option or input to a function is used. By default, the Octave:deprecated-option warning is enabled.

Octave:deprecated-property
     If the Octave:deprecated-property warning is enabled, a warning is issued when Octave encounters a graphics property that is obsolete and scheduled for removal from Octave. By default, the Octave:deprecated-property warning is enabled.

Octave:eigs:UnconvergedEigenvalues
     If the Octave:eigs:UnconvergedEigenvalues warning is enabled then the eigs function will issue a warning if the number of calculated eigenvalues is less than the number of requested eigenvalues. By default, the Octave:eigs:UnconvergedEigenvalues warning is enabled.

Octave:empty-index
     If the Octave:empty-index warning is enabled then Octave will emit a warning whenever indexing operators are used without an index, for example X(). By default, the Octave:empty-index warning is enabled.

Octave:erase:chararray
     If the Octave:erase:chararray warning is enabled then the erase function will issue a warning if the input pattern is a character array rather than a string or cell array of strings. By default, the Octave:erase:chararray warning is enabled.

Octave:function-name-clash
     If the Octave:function-name-clash warning is enabled, a warning is issued when Octave finds that the name of a function defined in a function file differs from the name of the file.  (If the names disagree, the name declared inside the file is ignored.) By default, the Octave:function-name-clash warning is enabled.

Octave:future-time-stamp
     If the Octave:future-time-stamp warning is enabled, Octave will print a warning if it finds a function file with a time stamp that is in the future. By default, the Octave:future-time-stamp warning is enabled.

Octave:glyph-render
     If the Octave:glyph-render warning is enabled, Octave will print a warning if the glyph for a character couldn't be rendered with the current font. By default, the Octave:glyph-render warning is enabled.

Octave:imag-to-real
     If the Octave:imag-to-real warning is enabled, a warning is printed for implicit conversions of complex numbers to real numbers. By default, the Octave:imag-to-real warning is disabled.

Octave:infinite-loop
     If the Octave:infinite-loop warning is enabled, a warning is printed when an infinite loop is detected such as for i = 1:Inf or while (1). By default, the Octave:infinite-loop warning is enabled.

Octave:language-extension
     Print warnings when using features that are unique to the Octave language and that may still be missing in MATLAB. By default, the Octave:language-extension warning is disabled. The --traditional or --braindead startup options for Octave may also be of use, see Command Line Options.

Octave:legacy-function
     If the Octave:legacy-function warning is enabled, a warning is issued when Octave encounters a function that MATLAB has suggested should be avoided.  The function may become obsolete at some point in the future and removed, in which case the warning will change to Octave:deprecated-function, and the function will continue to exist for two further versions of Octave before being removed. By default, the Octave:legacy-function warning is enabled.

Octave:logical-conversion
     If the Octave:logical-conversion warning is enabled, a warning is printed if an implicit conversion of an array from numerical to boolean occurs and any of the elements in the array are not equal to zero or one. By default, the Octave:logical-conversion warning is enabled.

Octave:lu:sparse_input
     If the Octave:lu:sparse_input warning is enabled, Octave will warn when the lu function is called with a sparse input and less than four output arguments.  In this case, sparsity-preserving column permutations are not performed and the result may be inaccurate. By default, the Octave:lu:sparse_input warning is enabled.

Octave:missing-glyph
     If the Octave:glyph-render warning is enabled, Octave will print a warning if the current font doesn't provide a glyph for a used character. By default, the Octave:missing-glyph warning is enabled.

Octave:missing-semicolon
     If the Octave:missing-semicolon warning is enabled, Octave will warn when statements in function definitions don't end in semicolons. By default the Octave:missing-semicolon warning is disabled.

Octave:mixed-string-concat
     If the Octave:mixed-string-concat warning is enabled, print a warning when concatenating a mixture of single and double quoted strings. By default, the Octave:mixed-string-concat warning is disabled.

Octave:nearly-singular-matrix
Octave:singular-matrix
     These warnings are emitted if a (nearly) singular matrix is inverted. By default, the Octave:nearly-singular-matrix and Octave:singular-matrix warnings are enabled.

Octave:neg-dim-as-zero
     If the Octave:neg-dim-as-zero warning is enabled, print a warning for expressions like

          eye (-1)

     By default, the Octave:neg-dim-as-zero warning is disabled.

Octave:noninteger-range-as-index
     If the Octave:noninteger-range-as-index warning is enabled, a warning is printed if an array is indexed with a range that contains non-integer values.  For example,

          a = [1 2 3 4 5];
          b = 2.2:4.2
          => 1.2  2.2  3.2
          a(b)
          => 2 3 4

     elicits a warning if the Octave:noninteger-range-as-index warning is enabled. By default, the Octave:noninteger-range-as-index warning is enabled.

Octave:num-to-str
     If the Octave:num-to-str warning is enabled, a warning is printed for implicit conversions of numbers to their UTF-8 encoded character equivalents when strings are constructed using a mixture of strings and numbers in matrix notation.  For example,

          [ "f", 111, 111 ]
          => "foo"

     elicits a warning if the Octave:num-to-str warning is enabled.  By default, the Octave:num-to-str warning is enabled.

Octave:possible-matlab-short-circuit-operator
     If the Octave:possible-matlab-short-circuit-operator warning is enabled, Octave will warn about using the not short circuiting operators & and | inside if or while conditions.  They normally never short circuit, but they do short circuit when used in a condition. By default, the Octave:possible-matlab-short-circuit-operator warning is enabled.

Octave:pow2:imaginary-ignored
     If the Octave:pow2:imaginary-ignored warning is enabled, a warning is printed if either input to pow2 is complex. By default, the Octave:pow2:imaginary-ignored warning is enabled.

Octave:recursive-path-search
     If the Octave:recursive-path-search warning is enabled, Octave will issue a warning if addpath is used with double trailing slashes. By default, the Octave:recursive-path-search warning is enabled.

Octave:remove-init-dir
     The path function changes the search path that Octave uses to find functions.  It is possible to set the path to a value which excludes Octave's own built-in functions.  If the Octave:remove-init-dir warning is enabled then Octave will warn when the path function has been used in a way that may render Octave unworkable. By default, the Octave:remove-init-dir warning is enabled.

Octave:reload-forces-clear
     If several functions have been loaded from the same file, Octave must clear all the functions before any one of them can be reloaded.  If the Octave:reload-forces-clear warning is enabled, Octave will warn you when this happens, and print a list of the additional functions that it is forced to clear. By default, the Octave:reload-forces-clear warning is enabled.

Octave:separator-insert
     Print warning if commas or semicolons might be inserted automatically in literal matrices. By default, the Octave:separator-insert warning is disabled.

Octave:shadowed-function
     If the Octave:shadowed-function warning is enabled, Octave will warn if a path is added to the search path that contains functions that shadow core functions. By default, the Octave:shadowed-function warning is enabled.

Octave:single-quote-string
     Print warning if a single quote character is used to introduce a string constant. By default, the Octave:single-quote-string warning is disabled.

Octave:sparse:double-conversion
     If the Octave:sparse:double-conversion warning is enabled, a warning is printed when an implicit conversion from a full, single array occurs during the creation of a sparse array. By default, the Octave:sparse:double-conversion warning is enabled.

Octave:sqrtm:SingularMatrix
     If the Octave:sqrtm:SingularMatrix warning is enabled, a warning is printed if the matrix square root function sqrtm is called with an input matrix that is singular. By default, the Octave:sqrtm:SingularMatrix warning is enabled.

Octave:str-to-num
     If the Octave:str-to-num warning is enabled, a warning is printed for implicit conversions of strings to their numeric UTF-8 encoded byte sequences.  For example,

          "abc" + 0
          => 97 98 99

     elicits a warning if the Octave:str-to-num warning is enabled. By default, the Octave:str-to-num warning is disabled.

Octave:LaTeX:internal-error
     If the Octave:LaTeX:internal-error warning is enabled, a warning is printed whenever the LaTeX renderer for text in plots encounters an issue. By default, the Octave:LaTeX:internal-error warning is enabled.

Octave:unimplemented-matlab-functionality
     If the Octave:unimplemented-matlab-functionality warning is enabled, a warning is printed when a MATLAB code construct is used which the Octave interpreter parses as valid, but for which Octave does not yet implement the functionality. By default, the Octave:unimplemented-matlab-functionality warning is enabled.

Octave:variable-switch-label
     If the Octave:variable-switch-label warning is enabled, Octave will print a warning if a switch label is not a constant or constant expression. By default, the Octave:variable-switch-label warning is disabled.

Enabling and Disabling Warnings
-------------------------------

The warning function also allows you to control which warnings are actually printed to the screen.  If the warning function is called with a string argument that is either "on" or "off" all warnings will be enabled or disabled.

It is also possible to enable and disable individual warnings through their string identifications.  The following code will issue a warning

     warning ("example:non-negative-variable",
              "'a' must be non-negative.  Setting 'a' to zero.");

while the following won't issue a warning

     warning ("off", "example:non-negative-variable");
     warning ("example:non-negative-variable",
              "'a' must be non-negative.  Setting 'a' to zero.");