Exception firing logic
Posted: 16.06.2006, 13:59
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 :
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
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;
...
Thanks in advance,
Peter