Programming Previous page   Next Page

Regenerating an Error

Use the rethrow function to regenerate an error that has previously been thrown. You may want to do this from the catch part of a try-catch block, for example, after performing some required cleanup tasks following an error.

This is how you would rethrow an error in a try-catch block:

rethrow generates an error based on the err input argument that you provide. This argument must be a MATLAB structure with at least the following two fields.

Field Name
Description
message
Text of the error message
identifier
Message identifier of the error message

If you simply want to regenerate the last error that occurred, the lasterror function returns a structure that can then be passed directly to rethrow.


Previous page  Identifying the Cause Message Identifiers Next page

© 1994-2005 The MathWorks, Inc.