MATLAB Function Reference |
Syntax
error('message') error('message',a1,a2, ...) error('message_id','message') error('message_id','message',a1,a2,...)
Description
error('message')
displays an error message and returns control to the keyboard. The error message contains the input string message
.
The error
command has no effect if message
is a null string.
error('message',a1,a2,...)
displays a message string that contains formatting conversion characters, such as those used with the MATLAB sprintf
function. Each conversion character in message
is converted to one of the values a1, a2, ...
in the argument list.
Note
MATLAB converts special characters (like \n and %d ) in the error message string only when you specify more than one input argument with error . See Example 3 below.
|
error('message_id','message')
attaches a unique message identifier, or message_id
, to the error message. The identifier enables you to better identify the source of an error. See Message Identifiers and Using Message Identifiers with lasterr in the MATLAB documentation for more information on the message_id
argument and how to use it.
error('message_id','message',a1,a2, ...)
includes formatting conversion characters in message
, and the character translations a1, a2, ...
Example 1
The error
function provides an error return from M-files:
The returned error message looks like this:
Example 2
Specify a message identifier and error message string with error
:
In your error handling code, use lasterr
to determine the message identifier and error message string for the failing operation:
[errmsg, msgid] = lasterr errmsg = The angle specified must be less than 90 degrees. msgid = MyToolbox:angleTooLarge
Example 3
MATLAB converts special characters (like \n
and %d
) in the error message string only when you specify more than one input argument with error
. In the single argument case shown below, \n
is taken to mean backslash-n
. It is not converted to a newline character:
error('In this case, the newline \n is not converted.') ??? In this case, the newline \n is not converted.
But, when more than one argument is specified, MATLAB does convert special characters. This holds true regardless of whether the additional argument supplies conversion values or is a message identifier:
error('ErrorTests:convertTest', ... 'In this case, the newline \n is converted.') ??? In this case, the newline is converted.
See Also
lasterr
, lasterror
, rethrow
, errordlg
, warning
, lastwarn
, warndlg
, dbstop
, disp
, sprintf
erf, erfc, erfcx, erfinv, erfcinv | errorbar |
© 1994-2005 The MathWorks, Inc.