rethrow - Reissue error

Syntax

rethrow(err)

Description

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.

Remarks

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.

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(lasterror)
end

See Also

error, lasterror, try, catch, dbstop

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS