Using raise without MadExcept getting involved
-
- Posts: 9
- Joined: Fri Aug 13, 2004 9:47 am
- Location: Australia
Using raise without MadExcept getting involved
Hi,
I am trying out MadExcept and all was looking good until I noticed MadExcept gets involved if I use raise. I declare an exception class as follows :
type
TE_Error = class(Exception);
And then in an OnBeforePost event I may check the validity of some values. For example :
if tCodesCode.AsString = '' then begin
eCode.SetFocus;
raise TE_Error.Create('A location code must be entered.');
end; {if}
if tCodesDescription.AsString = '' then begin
eDescription.SetFocus;
raise TE_Error.Create('A location code description must be entered.');
end; {if}
Any idea how to get MadExcept to ignore this code, but still have the raise display the error and cancel the post as it does without MadExcept.
Cheers,
Paul
I am trying out MadExcept and all was looking good until I noticed MadExcept gets involved if I use raise. I declare an exception class as follows :
type
TE_Error = class(Exception);
And then in an OnBeforePost event I may check the validity of some values. For example :
if tCodesCode.AsString = '' then begin
eCode.SetFocus;
raise TE_Error.Create('A location code must be entered.');
end; {if}
if tCodesDescription.AsString = '' then begin
eDescription.SetFocus;
raise TE_Error.Create('A location code description must be entered.');
end; {if}
Any idea how to get MadExcept to ignore this code, but still have the raise display the error and cancel the post as it does without MadExcept.
Cheers,
Paul
-
- Posts: 9
- Joined: Fri Aug 13, 2004 9:47 am
- Location: Australia
Using raise without MadExcept getting involved
Hi,
yes it helps, but I'm not sure how to use the unit in the overall context of my program. Where should I link it in etc. I define my exception class in each unit that I use it. Do I need the unit in all these or only in the main unit ?
Sorry, I'm a bit lost at the moment.
Cheers,
Paul
yes it helps, but I'm not sure how to use the unit in the overall context of my program. Where should I link it in etc. I define my exception class in each unit that I use it. Do I need the unit in all these or only in the main unit ?
Sorry, I'm a bit lost at the moment.
Cheers,
Paul
-
- Posts: 9
- Joined: Fri Aug 13, 2004 9:47 am
- Location: Australia
Yes, add it to the uses clause of any of your units or to the uses clause of your project (dpr). You can also rip the code and paste it into one of your units.paulcoshott wrote:I'm not sure how to use the unit. Do I just add it to my main units uses clause ?
See code below.paulcoshott wrote:And what do I insert where the (...) is in the ExceptionFilter procedure ?
exceptObject is the Exception object. It can be your exception class or anything else, e.g. EAccessViolation.paulcoshott wrote:Is the exceptObject my exception class object that I decared ?
Code: Select all
procedure ExceptionFilter(frozen : boolean;
exceptObject : TObject;
exceptAddr : pointer;
crashedThreadId : dword;
var bugReport : string;
var screenShot : string;
var canContinue : boolean;
var handled : boolean);
begin
if (exceptObject <> nil) and (exceptObject is TE_Error) then begin
// here you can do with the exception whatever you like
// e.g. you can show a standard information box
// please note that whatever you do here should be thread safe
// except if you told madExcept to call your handler in the context of
// the main thread
MessageBox(0, pchar(EDBEditError(exceptObject).Message), 'Error...', MB_ICONERROR);
// tell madExcept that you've already taken care of the exception
// as a result madExcept will not show its exception box this time
handled := true;
end;
end;
-
- Posts: 9
- Joined: Fri Aug 13, 2004 9:47 am
- Location: Australia
-
- Posts: 9
- Joined: Fri Aug 13, 2004 9:47 am
- Location: Australia
Hi,
I am able to compile the following code, and while debuging, the code is being executed, but it is not handling the error, and the MadExcept window is displayed. In the bug report, the Exception Class is listed as TE_Error. The unit is included in my main unit.
Any idea what I am doing wrong ?
==========================================
unit ExceptionFilterUnit;
interface
uses
Windows, SysUtils;
type
TE_Error = class(Exception);
implementation
uses madExcept;
procedure ExceptionFilter(frozen : boolean;
exceptObject : TObject;
exceptAddr : pointer;
crashedThreadId : dword;
var bugReport : string;
var screenShot : string;
var canContinue : boolean;
var handled : boolean);
begin
if (exceptObject <> nil) and (exceptObject is TE_Error) then begin
MessageBox(0, pchar(TE_Error(exceptObject).Message), 'Error...', MB_ICONERROR);
CanContinue := True;
Handled := True;
end;
end;
initialization
RegisterExceptionHandler(ExceptionFilter, false);
end.
===========================================
Cheers,
Paul
I am able to compile the following code, and while debuging, the code is being executed, but it is not handling the error, and the MadExcept window is displayed. In the bug report, the Exception Class is listed as TE_Error. The unit is included in my main unit.
Any idea what I am doing wrong ?
==========================================
unit ExceptionFilterUnit;
interface
uses
Windows, SysUtils;
type
TE_Error = class(Exception);
implementation
uses madExcept;
procedure ExceptionFilter(frozen : boolean;
exceptObject : TObject;
exceptAddr : pointer;
crashedThreadId : dword;
var bugReport : string;
var screenShot : string;
var canContinue : boolean;
var handled : boolean);
begin
if (exceptObject <> nil) and (exceptObject is TE_Error) then begin
MessageBox(0, pchar(TE_Error(exceptObject).Message), 'Error...', MB_ICONERROR);
CanContinue := True;
Handled := True;
end;
end;
initialization
RegisterExceptionHandler(ExceptionFilter, false);
end.
===========================================
Cheers,
Paul
You have declared TE_Error in this unit. And I'm sure you have it declared somewhere else, too. So you have two declarations of TE_Error and they are not identical! If you ask "if exceptObject is TE_Error" you're asking "if exceptObject is ExceptionFilterUnit.TE_Error", which is surely not what you want to do. There are 2 ways to solve this:
(1) Only declare TE_Error once. Import the unit in which it is defined in your ExceptionFilterUnit. Or put the code of the ExceptionFilterUnit into the unit where you've defined TE_Error.
(2) Or change it like this:
if (exceptObject <> nil) and (exceptObject.ClassName = 'TE_Error') then begin
This works only for TE_Error exceptions, but not for exception classes which are descendants of TE_Error. So I'd recommend to use (1).
(1) Only declare TE_Error once. Import the unit in which it is defined in your ExceptionFilterUnit. Or put the code of the ExceptionFilterUnit into the unit where you've defined TE_Error.
(2) Or change it like this:
if (exceptObject <> nil) and (exceptObject.ClassName = 'TE_Error') then begin
This works only for TE_Error exceptions, but not for exception classes which are descendants of TE_Error. So I'd recommend to use (1).
SAME TOPIC
hi,
I want to do exactly the same (custom Exception-class) and it worked fine until I updated to madExcept 2.7c. Now it takes quite a while before *any* exception is handled by my custom madExceptHandler!
I guess madExcept is collecting all the new hardware information etc. but in case of my custom Exception-class I don't need any additional information!
Is there a solution?
thx,
Tom
I want to do exactly the same (custom Exception-class) and it worked fine until I updated to madExcept 2.7c. Now it takes quite a while before *any* exception is handled by my custom madExceptHandler!
I guess madExcept is collecting all the new hardware information etc. but in case of my custom Exception-class I don't need any additional information!
Is there a solution?
thx,
Tom
-
- Posts: 9
- Joined: Fri Aug 13, 2004 9:47 am
- Location: Australia
Hi,
I had the exact same problem. Sometimes I would get the exception (either the madExcept one or my own exception) in 3 to 4 seconds, and sometimes it could take over 30 seconds.
I just went through and unticked almost everything and it is instant again. I will start adding bits and let you know what I find.
Paul
I had the exact same problem. Sometimes I would get the exception (either the madExcept one or my own exception) in 3 to 4 seconds, and sometimes it could take over 30 seconds.
I just went through and unticked almost everything and it is instant again. I will start adding bits and let you know what I find.
Paul