Added a small example. That's sort of how we add some information to already given exception-information and show it in a message-box.
Code: Select all
initialization
exHandler := TEHandler.Create;
RegisterExceptionHandler(OnBeforeDialog, stTrySyncCallAlways, epMainPhase);
finalization
FreeAndNil(exHandler);
procedure OnBeforeDialog(const exceptIntf: IMEException; var handled: boolean);
var
errMsg: string;
begin
errMsg := GetErrorMessage(exceptIntf.ExceptMessage, exceptIntf.ExceptClass, exceptIntf.RelatedObject);
ErrorDialog.Excecute(errMsg);
end;
function GetErrorMessage(exceptMsg: string; exceptClassName: string; exceptObj: TObject): string;
var
additionalInfos: string;
objinfos: string;
begin
additionalInfos := 'OS version:' + Linebreak + OS.Info.GetText + Linebreak + Linebreak;
additionalInfos := additionalInfos + 'Software version:' + Linebreak + OurSoftware.Name + Linebreak + Linebreak;
if not Assigned(exceptObj) then
objinfos := Format('%s'), ['nil']);
else
if exceptObj is TOurCustomObjekt then
objinfos := Format('%s [%s]', [TOurCustomObjekt(exceptObj).Name, exceptObj.ClassName])
else
if exceptObj is TComponent then
objinfos := Format('%s [%s]', [TComponent(exceptObj).Name, exceptObj.ClassName])
else
objinfos := Format('%s'), ['nil']);
additionalInfos := additionalInfos + 'Exception in:'+ Linebreak + objinfos + Linebreak + Linebreak;
// Fix because output is different when exceptObj is TOurCustomObjekt
if exceptObj is TOurCustomObjekt then
begin
firstline := System.Pos(LineBreak, ExceptMessage);
System.Delete(ExceptMessage, 1, firstline + 1);
end;
Result := 'Some error occured: '+ Linebreak + exceptMsg + Linebreak + additionalInfos;
end;
If it's a TOurCustomObjekt, then ExceptMessage will be:
'TestObject ano domini'#$D#$A'Zugriffsverletzung bei Adresse 0000000001ED8DEC in Modul ''OurSoftware.exe''. Lesen von Adresse 00000000000004EC.'
Anything else, e.g. a TListView (TComponent):
'Zugriffsverletzung bei Adresse 0000000001EC6EE1 in Modul ''OurSoftware.exe''. Schreiben von Adresse 0000000000000730.'
Sure i can cut off this first line, but maybe i misunderstood something using ExceptMessage.