开发者

How to call APPCRASH event in Delphi applications?

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜