How to save all the exceptions of type "EAccessViolation"?

delphi package - automated exception handling

Re: How to save all the exceptions of type "EAccessViolation

Postby madshi » Tue Jul 31, 2018 5:04 pm

Have you run this inside or outside of the IDE debugger?

I've tried this in a simple test project:

Code: Select all
procedure HiddenHandler(const exceptIntf: IMEException; var handled: boolean);
begin
  handled := true;
end;

var i1   : integer;
    time : dword;
begin
  RegisterHiddenExceptionHandler(HiddenHandler, stDontSync);

  time := GetTickCount;
  for i1 := 0 to 999 do
    try
      raise Exception.Create('test');
    except end;
  time := GetTickCount - time;
  MessageBoxA(0, PAnsiChar(AnsiString(IntToStr(time) + ' ms')), 'time', 0);
end.

It takes 3.8 seconds on my development PC. That's about 3.8 milliseconds per exception. Of course it'd be nice to have no delay at all. But I think 3.8 milliseconds per exceptions is so terribly bad?
madshi
Site Admin
 
Posts: 9826
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to save all the exceptions of type "EAccessViolation

Postby car_hack89 » Thu Aug 02, 2018 12:50 am

Hi,

madshi wrote:Have you run this inside or outside of the IDE debugger?

Outside of the IDE debugger

I understand that in your test the time is good, 3.8 seconds for the 1,000 iterations, but the performance can change, adding the following variants:

1. The time, also increases if within the try-except is added
     more code apart from the raise Exception,
     for example creation of TDataSet's, etc.
2. The performance changes depending on the platform
     the application, x32 or x64 bits
3. PC hardware

I appreciate the support, but HiddenExceptionHandler I can not use it, in an Application Server (multithreading application with high level of concurrency), where performance is a vital element, but thank you very much.

Just a question. Considering my objective, which is to save in a file the error message and the respective call stack which are Access Violation, I did the following,
and I was able to solve my goal, and without any impact on my performance:

Code: Select all
unit madExcept;

...
var OnAppHookExceptions: procedure(const pException: TObject; const exceptAddr: Pointer) = nil;
...

implementation
...

   procedure InterceptFreeExceptObject(exceptObject: TObject);
   begin
      ...
      if (GetCurrentThreadId <> HandleExceptionTid) and
        ((@OnAppHookExceptions <> nil) Or ((HiddenHandlers ...) or (HiddenHandlersOO ...))) and
       (exceptObject <> nil) and ... then begin
       if @OnAppHookExceptions <> nil then
          OnAppHookExceptions(exceptObject, System.ExceptAddr);
         if ((HiddenHandlers ...) or (HiddenHandlersOO ...)) then
            HandleException(etHidden, ...);      
      end;//if
     ...
   end;
   
   procedure HandleHiddenException(exceptObject: TObject; RaiseList: pointer);
   var ...;
   begin
      if exceptObject <> nil then begin
        try
          ...
       except end;
       if (GetCurrentThreadId <> HandleExceptionTid) and
          ((@OnAppHookExceptions <> nil) Or ((HiddenHandlers ...) or (HiddenHandlersOO ...))) and (RaiseList <> nil) and
         (MadException(...)...) and
         IsValidObject(...) then begin
          ea:= nil;
            TryRead(...);
         if @OnAppHookExceptions <> nil then
             OnAppHookExceptions(exceptObject, ea);
            if ((HiddenHandlers ...) or (HiddenHandlersOO ...)) then
               HandleException(etHidden, ...);
       end;
     end;
   end;


Any suggestion or opinion of the source code added to the madExcept unit?

Thanks in advance.
car_hack89
 
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Postby car_hack89 » Mon Aug 06, 2018 1:45 pm

Any suggestion or opinion of the source code added to the madExcept unit?

Thanks in advance.
car_hack89
 
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Postby madshi » Thu Aug 09, 2018 1:47 pm

I suppose it should work fine that way.
madshi
Site Admin
 
Posts: 9826
Joined: Sun Mar 21, 2004 5:25 pm

Previous

Return to madExcept

Who is online

Users browsing this forum: No registered users and 7 guests