Reputation: 3131
I am using Visual Studio 2005.
I am using SetUnhandledExceptionFilter to call my custom exception filter function when some unexpected error will happen. My custom filter function is called only if the unexpected error is Operating sytem error like Access Violation.
When the exception is C++ exception , raised with throw, my custom exception filter is not called, but still sometimes is called. Why is this ?
Thank you
Upvotes: 0
Views: 2488
Reputation: 5335
See http://www.debuginfo.com/articles/debugfilters.html for some techniques preventing someone from overwriting your unhandled exception filter.
Upvotes: 0
Reputation: 2947
You mixed up two different things:
For structured exceptions, you can specify a handler function with SetUnhandledExceptionFilter
. A similar concept exists for C++ exceptions. Here you use the function set_unexpected
or set_terminate
.
Your terminate handler should terminate the application whereas the unexpected handler could also throw (another) exception type. Thus you can catch "foreign" exceptions globally and map them to a exception type of your choice.
Upvotes: 3
Reputation: 8149
SetUnhandledExceptionFilter() is called when a structured exception is thrown and there isn't a handler to catch the exception. Structured exceptions are not the same as C++ exceptions. Thats why SetUnhandledExceptionFilter() isn't being called: you are throwing a C++ exception, not a structured exception.
Structured exceptions are a language-independent exception handling mechanism provided by Windows itself. A good place to read about them is here. You thrown a structured exception using the RaiseException() API function, and you catch them (in C/C++) using the __try and __except keywords.
Upvotes: 2
Reputation: 11
Because when you throw something and it is catched by something, "SetUnhandledExceptionFilter" will not be used. So I guess some exceptions you throw are catched either by you or by some library (or something) you use.
int main(){
try {
//exception 1 thrown
} catch (...){
// exception 1 handling
}
// exception 2 thrown
}
// no catch for exception 2, use UnhandledExceptionFilter
Upvotes: -1