function [hasDBError, dbstat] = disabledberror(allerror)
%DISABLEDBERROR turns off "dbstop if error" and returns previous
%status.

%   Copyright 1984-2002 The MathWorks, Inc.
%   $Revision: 1.4.4.1 $  $Date: 2004/12/20 16:45:11 $

if (nargin == 0)
    allerror = false;
end

% turn off "dbstop if error" while in the try-catch
dbstat = dbstatus;
hasDBError = false;

if ~isempty(dbstat)
  if (any(strcmp({dbstat.cond},'error')))
      hasDBError = true;
      dbclear if error;
  end
  if (allerror && any(strcmp({dbstat.cond},'caught error')))
      hasDBError = true;
      dbclear if caught error;
  end
end
