MException
Creates an exception object that carries an identifier and a message.
Category: Programming > Programming Utilities
Syntax
ME = MException(errID, msg)
Builds an exception with the identifier errID and the message msg.
ME = MException(errID, msg, A1, ..., An)
Formats the message like sprintf with the extra arguments.
Description
Creating the object does not raise an error; use throw(ME) for that. Building an exception separately is useful to prepare it, add causes, or store it for later. Exceptions caught by catch ME are the same kind of object, so code can inspect ME.identifier to decide what to do and ME.message to show the user.
Input arguments
errID- Identifier of the form
component:mnemonic, with no spaces. msg- Message text, possibly with conversions such as
%dand%s.
Output arguments
ME- An
MExceptionobject with propertiesidentifier,message,cause,stackandCorrection.
Example
Building and throwing an exception
ME = MException('app:range', 'Value %d is too large', 99);
try
throw(ME)
catch e
disp(e.identifier)
disp(e.message)
end
Output
app:range
Value 99 is too large