www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/mbcGetLastError.m
function [mnemonic, component, msg, components] = mbcGetLastError(varargin) %MBCGETLASTERROR Split the last thrown error and return its parts % % [MNEMONIC, COMPONENT, MESSAGE, COMPONENTS] = MBCGETLASTERROR takes the % last thrown error and returns the various parts of it. % % [...] = MBCGETLASTERROR('MessageFormat', F) specifies how to process the % message string that is returned. The default value for F is 'standard' % which just strips off the error location. Specifying 'singleline' will % remove carriage returns and (if necessary) replace them with spaces. % % [...] = MBCGETLASTERROR(E) returns the information for the specified % MException object. % Copyright 2000-2008 The MathWorks, Inc. and Ford Global Technologies, Inc. % Process input arguments if nargin && isa(varargin{1}, 'MException') err = varargin{1}; varargin(1) = []; else error(message('mbc:mbc:ObsoleteUse')); end MsgStyle = 'standard'; for n = 1:2:length(varargin) switch lower(varargin{n}) case 'messageformat' MsgStyle = varargin{n+1}; end end % Default outputs mnemonic = 'UnknownError'; component = ''; components = ''; % Local copy of the identifier id = err.identifier; % How many bits have been found numFound = 0; % Looping variables endPoint = length(id); currentPoint = length(id); % Extract the mnemonic and component information - this loop is JIT'ed while currentPoint >= 0 % Test for the delimiter or implicit delimiter at beginning of string if currentPoint == 0 || id(currentPoint) == ':' if numFound == 0 mnemonic = id(currentPoint+1:endPoint); else component = id(currentPoint+1:endPoint); components = id(1:currentPoint-1); break end % Increment the number of found bits and the next endPoint numFound = numFound + 1; endPoint = currentPoint - 1; end currentPoint = currentPoint - 1; end % Now need to get the second line of the message - removing the line added % by the MATLAB dispatcher msg = err.message; if strcmp(MsgStyle, 'singleline') msg = regexprep(msg, '\n\s', ' '); msg = regexprep(msg, '\n', ' '); end