| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
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(MException). rethrow called with a structure input will be removed in a future version. |
rethrow(errorStruct)
rethrow(errorStruct) reissues the error specified by errorStruct. The currently running M-file 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 | 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.
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.
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
rethrow(MException), throw(MException), throwAsCaller(MException), try, catch, error, assert, dbstop
![]() | restoredefaultpath | rethrow (MException) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |