| MATLAB Function Reference | ![]() |
rethrow(err)
rethrow(err) reissues the error specified by err. The currently running M-file terminates and control returns to the keyboard (or to any enclosing catch block). The err argument must be a MATLAB® structure containing at least one of the following fields.
Fieldname | Description |
|---|---|
| message | Text of the error message |
| identifier | Message identifier of the error message |
| stack | Information about the error from the program stack |
See "Message Identifiers" in the MATLAB documentation for more information on the syntax and usage of message identifiers.
A convenient way to get a valid err structure for the last error issued is by using the lasterror function.
The err 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.
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(lasterror) end
error, lasterror, try, catch, dbstop
![]() | restoredefaultpath | rethrow (MException) | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |