- •If expression
- •If expression
- •Various errors can be generated. The mnemonic field is a string
- •It is false, displays the formatted string contained in errmsg. The errmsg
- •If a function handle is bound to more than one built-in or
- •Inline/feval
- •Inputname, mfilename.
- •Value to use when the optional argument argname is not present in the
- •Identifier : ''
- •Issued by matlab.
Various errors can be generated. The mnemonic field is a string
normally used as a tag related to the particular message.
From the command line, you can obtain the message identifier for an
error that has been issued using the MException.last function.
See also MException, MException/throw, try, catch, sprintf, dbstop,
errordlg, warning, disp, dbstack.
Reference page in Help browser
doc error
<Mexception> - Constructs MATLAB exception object.
MException Capture error information.
ME = MException(MSGID, ERRMSG, V1, V2, ..., VN) captures information
about a specific error and stores it in MException object ME.
MSGID is a character string that uniquely identifies the source of the
error, and is composed of at least two substrings separated by a colon
(such as COMPONENT:MNEMONIC). For more information, type HELP ERROR
and see MESSAGE IDENTIFIERS.
ERRMSG is a character string that informs the user about the cause of
the error and can suggest how to correct the faulty condition. The
ERRMSG string can include escape sequences such as \t or \n, as well as
any of the format conversion specifiers supported by the SPRINTF
function, such as %s or %d. For more information, type HELP SPRINTF.
Inputs V1, V2, ..., VN provide values that replace any conversion
specifiers in the ERRMSG string.
Examples:
% Example 1 - Check the identifier of a MATLAB exception.
try
fid = fopen('noSuchFile.dat');
mydata = fread(fid);
fclose(fid);
catch ME
if strcmp(ME.identifier, 'MATLAB:FileIO:InvalidFid')
disp('Could not find the specified file.');
rethrow(ME);
end
end
% Example 2 - Create your own exception.
inputstr = input('Type a variable name:', 's');
if ~exist(inputstr, 'var')
ME = MException('MyComponent:noSuchVariable', ...
'Variable %s not found', inputstr);
throw(ME);
end
MException methods:
throw - Issue exception and terminate function
rethrow - Reissue existing exception and terminate function
throwAsCaller - Issue exception as if from calling function
addCause - Record additional causes of exception
getReport - Get error message for exception
last - Return last uncaught exception
MException public fields:
identifier - Character string that uniquely identifies the error
message - Formatted error message that is displayed
stack - Structure containing stack trace information
cause - Cell array of MExceptions that caused this exception
See also error, assert, try, catch, dbstack.
Reference page in Help browser
doc Mexception
<assert> - Generate an error when a condition is violated.
ASSERT Generate an error when a condition is violated.
ASSERT(EXPRESSION) evaluates EXPRESSION and, if it is false, displays the
error message 'Assertion Failed'.
ASSERT(EXPRESSION, ERRMSG) evaluates EXPRESSION and, if it is false,
displays the string contained in ERRMSG. When ERRMSG is the last input to
ASSERT, MATLAB displays it literally, without performing any substitutions
on the characters in ERRMSG.
ASSERT(EXPRESSION, ERRMSG, VALUE1, VALUE2, ...) evaluates EXPRESSION and, if
