Exception firing logic

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
Petya
Fresh Boarder
Fresh Boarder
Posts: 21
Joined: 16.08.2005, 16:07

Exception firing logic

Post by Petya »

Hello folks,

I found that if the SQL server cannot execute a query and reports an error ZQuery sometimes throws EDatabaseError, sometimes the generic Exception. I haven't got time yet to investigate when does it throw which exception, but I'd like to reserve the general type for other errors than database. I use Delphi 5 and MS SQL Server 2000. See my code :

Code: Select all

const EOL = #13 + #10 ;

procedure ...
var QueryText: string;
begin
  ...
  if DatabaseXConnected then
  try with TZQuery.Create(Form1) do try
    Connection:=Form1.ZConnectionX;
    SQL.Add(' ... ');
    ExecSQL;  // or Open; respectively
    ...
  finally
    QueryText:=SQL.Text;
    if IniFile.ReadInteger('Log','AllSQL',0)=1 then FileLog(Database,SQL.Text);
    Destroy;
  end;
  except
    on E: EDatabaseError do FileLog(DatabaseErrors,QueryText + EOL + E.Message); 
    on E: Exception do FileLog(Errors,E.ClassName + ' <CUSTOM DESCRIPTION>' + EOL + E.Message);
  end;
  ...
Can someone tell me which case ZQuery fires general exception type Exception and which case EDatabaseError ? I must separate database errors from others.

Thanks in advance,

Peter
Post Reply