Programming |
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
.
Note
lasterror is not the same as lasterr . The lasterror function returns a structure array that contains the message string and message identifier for the last error, and may contain more information in future versions of MATLAB. The lasterr function returns one or two character arrays that contain only the message string and identifier.
|
Identifying the Cause | Message Identifiers |
© 1994-2005 The MathWorks, Inc.