Disable exception handling and let Windows catch it?

I want to turn off Delphi exception capture and let Windows catch it - make it create a window like "AppName crashed. Debug, Send", add this to application events, create a memory dump, etc.

By default, Delphi catches all exceptions in TApplication.Run ... How can I avoid this without changing Forms.pas?

+6
source share
4 answers

You can set JITEnable to "1" or higher (default is "0"). With "1", non-native exceptions, with a higher value of "1", all exceptions will be handled by JIT or WER (depending on the system).

Perhaps this is not what you want. With this solution, any qualified exception will be passed to the OS, no matter if they are processed by code or not. Clarification (performed outside the debugger):

 procedure TForm1.Button1Click(Sender: TObject); begin raise EAccessViolation.Create('access denied'); end; procedure TForm1.Button2Click(Sender: TObject); begin try PInteger(0)^ := 0; except end; end; initialization JITEnable := 1; 

The first example is a natural exception, it will be handled by the application exception handling mechanism if JITEnable is 1. But the second example will call JIT / WER.

+4
source

You can add an OnException handler that re- OnException exception:

 class procedure TMainForm.OnException(Sender: TObject; E: Exception); begin raise Exception(AcquireExceptionObject); end; initialization Application.OnException := TMainForm.OnException; 

I'm not sure why you would like to do this at all. It is more common to use a tool, such as madExcept or EurekaLog, to display an error dialog box that provides much more useful information than a system dialog.

+8
source

Add your own handler. Application.OnException is probably what you want. Better than leaving this to windows, as you get different types of behavior depending on the environment. For example, if Windows Error Reporting is enabled, it will ask the user if he wants to send an error report to MS.

Like Mr. Heffernan, I recommend you look at something like EurekaLog.

+3
source

AS. I agree with the above voices that this is rather strange. I also agree that practically binding to TApplication.OnException will probably be enough ("if it looks like a duck ...")

However, if you really want RTL to ignore exceptions, there are ways.

Exception handlers are a plugin for low-level RTL, as well as heap management, etc.

You can see KOL (Key Object Library). In Delphi, 5 times I managed to create a 2K DLL.

This required the absence of many ordinary words, taken for granted. An exception was among them.

To enable exceptions in replacing the KOL RTL system, you had to do a few $ DEFINE, and then the code to add exception support for the IDE was unlocked.

I believe that you can still get this modular RTL version and grep for this $ IfDef and see which code is replaced with which. I believe there is a fair chance that you can undo this and make Windows avoid using Delphi RTL over exceptions. I donโ€™t remember the details, but I believe that the Exception Delphi RTL handler is simply registered in the Windows kernel as a callback. And you can probably register it (register a null callback). I believe that you can find it in the RTL warehouse, but the modular RTL KOL will simply simplify the search.

0
source

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


All Articles