C++ - catch all exceptions?

余生长醉 提交于 2019-12-11 06:51:32

问题


I want to inject a DLL into a process. Once this DLL is in there, it should catch & properly handle all access violation exceptions which occur in the process. Is there any way to accomplish this?


回答1:


How about SetUnhandledExceptionFilter( function )?

function's prototype is:

LONG __stdcall ExceptionHandler(EXCEPTION_POINTERS *ExceptionInfo);

I've used this function to create crash dumps, etc.




回答2:


You can use Structured Exception Handling (SEH) to catch such exceptions. Specifically, this Windows function seems to be what you want to do.




回答3:


To complete the collection, you can also use AddVectoredExceptionHandler.




回答4:


Pre XP, you cannot catch all exceptions. XP or later, you should use AddVectoredExceptionHandler(1, handler), although you are not guaranteed that you will always be the first vectored exception handler.



来源:https://stackoverflow.com/questions/7288222/c-catch-all-exceptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!