How to trigger APPCRASH event in Delphi applications?

You can see this as a dumb question, but I wonder how I can terminate my application with delphi with an APPCRASH error. (also known as Do Not Submit!)

Thnx in advance

+3
source share
2 answers

You can enable this function by setting the global variable JITEnable in System. If you set the value to 1, all external exceptions (i.e. Access Violations, illegal instructions and any exception other than Delphi) will cause the desired response. If you set the value to 2, any exception will cause this behavior. In any case, this will happen only when you are not debugging the application. The debugger will always receive the first crack and will notify you of the impending death. Here is 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.
+11
source

Instead of going around paths to handle exceptions, you may simply not use:

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;

Crashexecuted in a new thread. There are no ANY exception handlers in this thread . Any exception in such a thread will be fatal to the application.

+3
source

Source: https://habr.com/ru/post/1796139/


All Articles