Code covered by the BSD License  

Highlights from
Error API for Application Development

image thumbnail

Error API for Application Development

by

 

04 Apr 2006 (Updated )

An API to assist with error reporting in MATLAB applications

xError(id,str,varargin)
function xError(id,str,varargin)
%XERROR Throws an error, recording the details in the log file
%
% xError(id,str,varargin)
%
% Usage is the same as built-in error, except that the identifier
% is compulsory (though it can be empty) and the "str" input is
% always processed using sprintf.
% 
% The error thrown here can be retrieved (without any additional
% lines such as "error using ==> my_function") using xLastError or
% xLastErr.  It is also written to the log file.
%
% See also: error, xLog, xLastError, xLastErr

% Copyright 2006-2010 The MathWorks, Inc.

msg = sprintf(str,varargin{:});

% Write the current call stack to the log file
d = dbstack('-completenames');
s = struct('message',msg,'identifier',id,'stack',d(2:end));
xLogError(s);

% Store for later
xLastError(s);

% Throw a real MATLAB error
if isempty(id)
    error('%s',msg);
else
    error(id,'%s',msg);
end

Contact us