MATLAB Programming

MATLAB Programming MATLAB Programming

cda.psych.uiuc.edu
from cda.psych.uiuc.edu More from this publisher
23.06.2015 Views

8 Error Handling matrixMultiply(A, C) ** Both arguments must be double matrices Regenerating an Error Use the rethrow function to regenerate an error that has previously been thrown.Youmightwanttodothisfromthecatch part of a try-catch block, for example, after performing some required cleanup tasks following an error. This is the general method used to rethrow an error in a try-catch block: try - do_something - catch - do_cleanup - rethrow(lasterror) end rethrow generates an error based on the MATLAB structure you provide as an input argument. The input structure must have at least one of the message, identifier, andstack fields. Field Name message identifier stack Description Character array containing the text of the error message. Character array containing the message identifier of the error message. If the last error issued by MATLAB had no message identifier, then the identifier field is an empty character array. Structure providing information on the location of the error. The structure has fields file, name, and line, and is the same as the structure returned by the dbstack function. If lasterror returns no stack information, stack is a 0-by-1 structure having the same three fields. 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. 8-8

Handling and Recovering from an Error Note lasterror is not the same as lasterr. Thelasterror function returns a structure array that contains the message string, message identifier, and stack information for the last error, and might 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. 8-9

Handling and Recovering from an Error<br />

Note lasterror is not the same as lasterr. Thelasterror function returns<br />

a structure array that contains the message string, message identifier, and<br />

stack information for the last error, and might contain more information<br />

in future versions of <strong>MATLAB</strong>. The lasterr function returns one or two<br />

character arrays that contain only the message string and identifier.<br />

8-9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!