开发者

Programmatically catching windows close event when out of GDI resources

开发者 https://www.devze.com 2023-04-11 22:56 出处:网络
I\'m trying to catch all unexpected terminations in my process. I\'ve used these functions to catch all the unhandled errors and exceptions that i can think of, but still it\'s not enough:

I'm trying to catch all unexpected terminations in my process.

I've used these functions to catch all the unhandled errors and exceptions that i can think of, but still it's not enough:

    SetUnhandledExceptionFilter(OnUnhandledNativeException);

    set_terminate(set_terminateHandler);

    set_unexpected(set_unexpectedHandler);

    _set_purecall_handler(set_purecallHandler);

    _set_new_handler(HandleProgra开发者_StackOverflowmMemoryDepletion);       

    _set_invalid_parameter_handler(InvalidParameterHandler);

    signal(SIGABRT, sigabrt_handler); 
    signal(SIGINT, sigabrt_handler);
    signal(SIGTERM , sigabrt_handler);

These functions catch almost any error in the application.

But, when the application is terminated because of a GDI failure (for example GDI out of resources), non of these functions are called.

Does anyone know how i can catch GDI error events ?

I'm sure there must be some way to overload it and change the callback function.

And, does anyone know of any other weird scenarios where these functions just aren't enough ?

Note:

The exact error that it's not catching is "A required resource was unavailable".

This is caused when you create a lot of GDI objects and don't release them.

The program will crash because there aren't enough resources long before it runs out of memory.


  1. Some of the functions you listed (e.g. SetUnhandledExceptionFilter) set the handlers for the current thread. Therefore you should call them in each thread.
  2. You can add Vectored Exception Handling to the list (AddVectoredExceptionHandler).


If you're on Visual C++ __try __finally will usually do the trick. Note that this is not a portable solution.


Ok, solved the problem.

It WAS catching the crash.

The problem was that as part of the process of salvaging the data from the crash, it was opening a Form which was supposed to notify the user that an error has occurred.

Of course, we're out of GDI objects, so the Form can't be drawn, so that in itself threw and exception, we had another unhandled exception, and the process really crashed.

0

精彩评论

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

关注公众号