function varargout = errorHandler(msg, titleStr, errorID)
% Scope error-message handler
% Produces a modal dialog
% Accepts strings and cell-arrays of strings

% Copyright 2004-2010 The MathWorks, Inc.

% If the error string is empty, return early.
if isempty(msg)
    return;
end

if nargin < 2
    titleStr = uiscopes.message('TitleScopeError');
end

if iscell(msg),
    % Each cell is a separate line
    % Formatting handled by 'errordlg'
    formattedMsg = msg;
else
    formattedMsg = sprintf('%s', msg);
end

handleErrorDlg =  errordlg(uiservices.removeHyperlinks(formattedMsg), ...
    titleStr, 'modal');

% Tag of the error dialog is updated for testability. 
% The default tag set is based on the title string which may be localized
% g681411. On fixing this bug, if an option is given to specify tag as
% argument to errordlg, the tag can be added as argument in the line above.

set(handleErrorDlg,'tag','ScopeErrorDialog');

if nargin > 2
    set(handleErrorDlg, 'UserData', errorID);
end

if nargout
    varargout{1} = handleErrorDlg;
end

% [EOF]
