简体   繁体   English

C ++-捕获所有异常?

[英]C++ - catch all exceptions?

I want to inject a DLL into a process. 我想将DLL注入到进程中。 Once this DLL is in there, it should catch & properly handle all access violation exceptions which occur in the process. 一旦此DLL进入该目录,它应捕获并正确处理该过程中发生的所有访问冲突异常。 Is there any way to accomplish this? 有什么办法可以做到这一点?

How about SetUnhandledExceptionFilter( function )? SetUnhandledExceptionFilter( 函数 )怎么样?

function 's prototype is: 函数的原型是:

LONG __stdcall ExceptionHandler(EXCEPTION_POINTERS *ExceptionInfo);

I've used this function to create crash dumps, etc. 我已经使用此功能创建故障转储,等等。

You can use Structured Exception Handling (SEH) to catch such exceptions. 您可以使用结构化异常处理(SEH)来捕获此类异常。 Specifically, this Windows function seems to be what you want to do. 具体来说, Windows函数似乎是您想要执行的操作。

要完成收集,您还可以使用AddVectoredExceptionHandler

Pre XP, you cannot catch all exceptions. XP之前的版本无法捕获所有异常。 XP or later, you should use AddVectoredExceptionHandler(1, handler) , although you are not guaranteed that you will always be the first vectored exception handler. 在XP或更高版本中,应AddVectoredExceptionHandler(1, handler)使用AddVectoredExceptionHandler(1, handler) ,尽管不能保证您始终是第一个矢量化异常处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM