MATLAB: How to programmatically extract the line number at which a caught error occurred

MATLAB

How can I programmatically extract the line number at which a caught error occurred?

Best Answer

The line number at which a caught error occurred is stored in the MException object. For example, the error number is being extracted from the "mErr" MException object. in the following code:
try
surf
catch mErr
error_line = mErr.stack(end).line;
end