Matlab provides two mechanisms for signaling that something has gone wrong: the error
function and the language's exception-handling mechanisms MException
+ try
/catch
/throw
.
It looks like they are largely equivalent: The error
function and the MException
function have very similar syntax. Errors raised via error()
can be caught by a catch
, while the error-related tools (like dbstop if error
and lasterr
) seem to work with exceptions too.
Is there ever a reason to prefer error('Foo:Bar', 'Some human-readable message about bar')
to throw(MException('Foo:Bar', 'Some human-readable message'))
or vice versa?
(They're both built-ins, so you cannot just open (e.g.) error.m to see if one is a trivial wrapper around the other!)