Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call APPCRASH event in Delphi applications?

Tags:

delphi

You might see this as a dumb question, but I'm curious about how I can terminate my delphi-made application with APPCRASH error. (also known as "Don't send" error!!)

Thnx in advance

like image 409
Javid Avatar asked Mar 03 '11 20:03

Javid


2 Answers

You can enable this functionality by setting the global variable, JITEnable, in System. If you set it to 1, all external exceptions (ie. Access violations, illegal instructions, and any non-Delphi exception), will trigger the reaction you want. If you set it to 2, any exception will trigger that behavior. In either case this will only happen when you're not debugging the application. The debugger will always get first crack and will notify you of the impending doom. Here's a simple example:

{$APPTYPE CONSOLE}
uses
  SysUtils;

begin
  try
    JITEnable := 2;
    raise Exception.Create('Error Message');
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
like image 142
Allen Bauer Avatar answered Sep 24 '22 01:09

Allen Bauer


Instead of workaround paths for exception handling - you can just don't use any:

function Crash(Arg: Integer): Integer; stdcall;
begin
  Result := PInteger(nil)^;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  TID: Cardinal;
begin
  CloseHandle(CreateThread(nil, 0, @Crash, nil, 0, TID));
end;

Crash executes in a new thread. This thread doesn't have ANY exception handlers. Any exception in such thread will be fatal for application.

like image 21
Alex Avatar answered Sep 23 '22 01:09

Alex