Take the 2-minute tour ×

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

share|improve this question
I'm curious. Why? –  David Heffernan Mar 3 '11 at 20:32
@David: I just want to know. Like lots of apps, such as Photoshop,etc. –  Javid Mar 3 '11 at 20:40
Those apps don't intentionally terminate that way! –  David Heffernan Mar 3 '11 at 20:54

2 Answers 2

up vote 10 down vote accepted

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:


    JITEnable := 2;
    raise Exception.Create('Error Message');
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
share|improve this answer
it works but it only has one problem. The application stucks and when we want to close it, we can't (except using Task Manager). I didn't mark this answer as accepted although it looks like a standard one. –  Javid Mar 3 '11 at 22:11
If you're just wanting to "fast terminate" your application, you can do this: TerminateProcess(GetCurrentProcess, 1); That will summarily discharge your application with nary a whimper. Of course, if your application is doing important things at that point, things could go sideways very fast. –  Allen Bauer Mar 3 '11 at 23:48
@Allen: Thank you dear Allen Bauer, Your suggestions were useful. Marked them as accepted answer. Let me explain what I exactly meant by the previous comment. When I set JITEnable to 2 but when I raise an exception and I ask windows to close my app, it doesn't do it and it sticks until I terminate the process using Task Manager. –  Javid Mar 4 '11 at 9:17
@Javid, that is odd. Does my example exhibit the same behavior for you? If you have a smaller test-case where this happens, please enter it into our defect tracking system at qc.embarcadero.com. I'm using the latest version (internal post-Delphi XE builds). I suspect there could be something else causing your app to hang around. Do you have any threads blocked on IO requests or on some OS sync object? –  Allen Bauer Mar 4 '11 at 16:21
@Allen: No I don't have any. Anyway I'm using D2010 and I don't have XE; should I still report it to QC? –  Javid Mar 4 '11 at 21:09

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

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

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

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

share|improve this answer
-1 This doesn't answer the actual question, which was how to trigger a specific way of dealing with exceptions using the OS functionality. Allen's answer does so; yours demonstrates the absolute wrong way to deal with exceptions in threads and code in general. –  Ken White Mar 3 '11 at 21:32
Are you joking? –  Alexander Mar 3 '11 at 21:50
nice solution Alexander. It works as expected ;) –  Javid Mar 3 '11 at 22:09
no I'm not. The question was "How to trigger appcrash?", and your answer was "dereference a nil pointer in a thread". Delphi's default exception handlers will trap most (not all) exceptions and show an exception dialog; the only way to trigger appcrash (without intentionally writing terrible code) is the way Allen described. Sorry if you don't agree, but Allen's answer was more correct (as shown by the number of votes he's received), and I don't think yours was correct at all. That's the way SO works; today isn't your first day here, so you should know that by now. –  Ken White Mar 4 '11 at 0:59
@Ken White You're horrible wrong. Take some time to analyze this code before doing such claims. Naked thread doesn't have any exception handler. Including Delphi one. There will be no Delphi error dialog. Don't like dereferencing? Fine, write "raise Exception" - it doesn't matter. –  Alexander Mar 4 '11 at 13:33

Your Answer


