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 MException.rethrow. rethrow called with a structure input will be removed in a future version.
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:
Text of the error message
Message identifier of the error message
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.
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