Does Application.OnException work in a COM Dll?
I want to log some seemingly random errors I'm getting in a Delphi written COM DLL. How do I开发者_JAVA百科 do this? Is it possible to use the Application.OnException event handler? I have control of the COM DLL source, but not the calling application.
No. A DLL doesn't have an Application variable, since it's not an application.
The correct way to handle exceptions in a DLL is with try..except
blocks. The most basic technique is to put a try..except
block around each of your exported functions that will catch errors before they propagate outside of the DLL.
You might try creating your own global function called OnException and having the Except blocks call it and pass in the exception they receive, or something like that. That's basically what Application.OnException does; it can just do it automatically since it's got a single known point near the bottom of the call stack to put inside a try..except
block.
I don't think Application.OnException is going to work for you in a COM DLL. You may have to go right down to the low level stuff. Take a look at RaiseExceptionProc in the System unit. It should let you get the information you want.
精彩评论