Documentation Center

  • Trial Software
  • Product Updates

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(MException). 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

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.

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

More About

expand all

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.

See Also

| | | | | |

Was this topic helpful?