AppException still working - for some errors

delphi package - automated exception handling
Post Reply
Lace
Posts: 4
Joined: Wed Feb 15, 2006 3:25 pm
Location: Manchester, UK

AppException still working - for some errors

Post by Lace »

Hi

I understood that if MadExcept is enabled the AppException will not fire

There seem to be some exceptions

Database errors (I am using NativeDB to access a Sybase database)

ENativeDatasetErrors are not trapped by MadExcept, picked up by the original exception handler.

This behaviour is fine by me but I though you aught to know.

Regards Mike

Code pasted below in case you are interested

The DBError dialog get displayed, nothing from MadExcept

procedure TMain.AppException(Sender: TObject; E: Exception);
var Go, Ok, IE: Boolean;
X, Y: string;
Z: TFieldType;
begin
if not AsaSession1.Connected then begin
Application.ShowException(E);
Application.Terminate;
end else begin
Ok := True;
Go := False;
IE := False;
if (Sender is TDBEdit) or (Sender is TDBXGrid) then begin
if (Sender is TDBEdit) then begin
with Sender as TDBEdit do begin
X := Text;
Y := Field.DisplayName;
Z := Field.DataType;
end;
end else begin
with Sender as TDBXGrid do begin
X := InPlaceEditor.Text;
Y := SelectedField.DisplayName;
Z := SelectedField.DataType;
end;
end;
if (Z = ftFloat) or (Z = ftCurrency) then begin
if Format(SInvalidFloatValue, [X, Y]) = E.Message then begin
E.Message := Format('[ %s ] is not a valid floating point value.', [X]);
IE := True;
if DoCancel then begin
NotValid := True;
Go := True;
end;
end;
end;
if (Z = ftSmallInt) or (Z = ftInteger) or (Z = ftWord) then begin
if Format(SInvalidIntegerValue, [X, Y]) = E.Message then begin
E.Message := Format('[ %s ] is not a valid integer value.', [X]);
IE := True;
if DoCancel then begin
NotValid := True;
Go := True;
end;
end;
end;
if Z = ftDate then begin
if Format(SInvalidDate, [X, Y]) = E.Message then begin
E.Message := Format('[ %s ] is not a valid date.', [X]);
IE := True;
if DoCancel then begin
NotValid := True;
Go := True;
end;
end;
end;
end;
if (Sender is TDBCtrlGrid) and (E is EInvalidOperation) then begin
if E.Message = 'Cannot focus a disabled or invisible window' then begin
Go := True;
end;
end;
if not Go then begin
if Sender is TControl then begin
if TControl(Sender).Owner = nil then begin
E.Message := TControl(Sender).Name + #13#10#13#10 + E.Message;
end else begin
E.Message := TControl(Sender).Owner.Name + '.' +
TControl(Sender).Name + #13#10#13#10 + E.Message;
end;
end;
if Ok and (E is ENativeDatasetError) then begin
DbError.Memo1.Text := 'Database Error - Processing Aborted';
DbError.Memo2.Text := E.Message;
DbError.ShowModal;
end else begin
Application.ShowException(E);
end;
if not IE then begin
DataMod.LogE.ParamByName('xtype').Value := E.ClassName;
DataMod.LogE.ParamByName('xmess').Value := E.Message;
DataMod.LogE.ParamByName('xwho').Value := UserSeq;
try
DataMod.LogE.ExecProc;
except
end;
end;
end;
end;
end;
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

How is AppException connected to receive exceptions? Is it connected through Application.OnException?

Maybe NativeDB directly checks and calls Application.OnException internally. What you could do to work around it is to change your code like this:

Code: Select all

procedure TMain.AppException(Sender: TObject; E: Exception); 
begin
  madExcept.HandleException(etNormal, E);
end;
Normally this is not necessary, because madExcept hooks into Application.HandleException and Application.ShowException. However, if NativeDB directly calls Application.OnException, then this is not catched by madExcept.
Lace
Posts: 4
Joined: Wed Feb 15, 2006 3:25 pm
Location: Manchester, UK

AppException

Post by Lace »

How is AppException connected to receive exceptions? Is it connected through Application.OnException?

Yes it is.

I tried your work arround and it did not do anything

Thanks

Michael
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Are your sure that AppException is executed at all? Can you please set a breakpoint? If you call madExcept.HandleException, a madExcept exception box should occur (except if you configured madExcept to ignore this specific exception class or all exceptions or something like that).
Lace
Posts: 4
Joined: Wed Feb 15, 2006 3:25 pm
Location: Manchester, UK

Post by Lace »

Hi

I am sorry to have wasted your time

The errors in question where trapped (OnPostError event) and the dialog box was launched from there

Mike
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

:D
Post Reply