rethrow
Reissue error
Note
As of version 7.5, MATLAB® supports error handling that
is based on the MException
class. Calling rethrow
with
a structure argument, as described on this page, is now replaced by
calling rethrow with an MException
object, as described
on the reference page for rethrow
. rethrow
called with
a structure input will be removed in a future version.
Syntax
rethrow(errorStruct)
Description
rethrow(errorStruct)
reissues the error specified by errorStruct
. The
currently running function terminates and control returns to the keyboard
(or to any enclosing catch
block). The errorStruct
argument
must be a MATLAB structure containing at least the message
and identifier
fields:
Fieldname | Description |
---|---|
message | Text of the error message |
identifier | Identifier for the error |
stack | Information about the error from the program stack |
For information about error identifiers, see MException
.
Examples
rethrow
is usually used in conjunction with try, catch
statements
to reissue an error from a catch
block after performing catch
-related
operations. For example,
try do_something catch do_cleanup rethrow(previous_error) end
Tips
The errorStruct
input can contain the field stack
,
identical in format to the output of the dbstack
command.
If the stack
field is present, the stack of the
rethrown error will be set to that value. Otherwise, the stack will
be set to the line at which the rethrow occurs.
Extended Capabilities
Version History
Introduced before R2006a
See Also
rethrow
| throwAsCaller
| throw
| assert
| error
| MException
| try, catch