开发者

How to catch absolutely all exceptions / errors

I have a windows service application, running under WinXPe, which sometimes fails with an error and displays an message box to the user:

"The instruction at “” referenced memory at “0x00000000”. The memory could not be “read.” Press OK to exit the program

If the user clicks "Ok" the service is restarting.

I have tried to catch all unhandled exceptions with registering a eventhandler at AppDomain.CurrentDomain.UnhandledException in the handler I log the 开发者_StackOverflow社区exception details and exit the application. But the error I mentioned above is NOT handled from "UnhandledException".

The application is heavily multi threaded, using System.Threading.Timer and System.Threading.Thread. And it's using some third party libs, one of these libs are using native interop, I have no source of the native lib.

I tried to point out the error with an debugger attached, but the error doesn't show up ;) The application has to run several days before the error occurs.

I need a way to handle such a error.

Thanks


See Vectored Exception Handling

This is part of windows SEH (Structured Exception Handling) and IIRC here is precious few errors that you could not at least be notified of in such a case.

You will probably want to write any handling code directly to the native WIN32 API (in unsafe/unmanaged code) and using pre-allocated (static?) buffers only, because there will be many things unreliable at that moment in time.

Beware of/stay away from threading, locking primitives, memory allocations, disk IO; preferrably use Windows default API's to, e.g. restart the process or produce a minidump and things like that


That error is not a managed exception. It's a lower level memory access violation. Essentially a NULL pointer access in native code.

This is something you're supposed to be completely protect from in managed code, so it's likely one of your native libraries or the way you're using them. If the error only appears after a few days of execution, you might be best off first going through any native library calls, checking their signatures and making sure you pass them data that makes sense.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜