Re: Throwing exception from _invalid_parameter_handler



Doug Harrison [MVP] wrote:

I am wondering whether it is safe to throw a C++ exception from an invalid
parameter handler set with _set_invalid_parameter_handler. The documentation
mentions two actions the handler cat take: terminate the application or exit
silently. It doesn't explicitly mention throwing a C++ exception from the
handler function.

I'd think it's not OK to throw an exception, since the handler will be called from functions declared extern "C", which interacts with the usual /EHsc compiler option.

Well, that's a strong point. Let's assume for now that my code is compiled with /EHa. Can I still break anything inside the CRT if I throw an exception?


I would like to have invalid parameter handlers in place but I don't want to terminate the whole app if a buffer overflows, only the current work item. I wanted to avoid polluting my code with errno checking after every function call and throwing an exception seemed to be an elegant way of doing it.

Thanks,
-- Alex Fedotov


.