MATLAB Error Control Statement-try, catchMATLAB define some functions that are used to control error. The try-catch statement is an error control function, which is explained below. Try - catch statementTry-catch statement provides error handling control. General form of the try-catch statement is Syntax: Statements between try and catch execute first. If no error appears in executing statements between try and catch, MATLAB further executes the statements/code after the end keyword. If an error occurs during the execution of statements between try and catch, MATLAB executes statements between catch and end. Try-catch statement can be explained with the help of the following example. Example: Output: MException with properties: identifier: 'MATLAB:catenate:dimensionMismatch' message: 'Dimensions of arrays being concatenated are not consistent.' cause: {01 cell} stack: [31 struct] Correction: [] Following are the points while using a try/catch statement in MATLAB:
Example showing MException class object properties: Output: causeException = MException with properties: identifier: 'MATLAB:mycode:dimensions' message: 'dimension mismatch occured: First argument has 4 columns, while second argument has 3 columns.' cause: {} stack: [01 struct] Correction: [] Program TerminationProgram termination control allows to exit from our program at some point before its normal termination point.
Next TopicMATLAB return
|