C ++中的全局异常处理 [英] Global exception handling in C++

查看:404
本文介绍了C ++中的全局异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在C ++中实现全局异常处理吗?
我的要求是try ... catch块不在一段代码中使用,那么应该有一个全局异常处理程序处理所有未捕获的异常。

Can i implement global exception handling in C++? My requirement is try...catch block is not used in a piece of code then there should be a global exception handler which will handle all uncaught exception.

推荐答案

在C ++中, terminate 函数在未捕获异常时被调用。您可以使用 set_terminate 函数安装您自己的terminate处理程序。缺点是你的terminate处理程序永远不会返回;它必须使用某些操作系统原语终止您的程序。默认值只是调用 abort()

In C++ the terminate function is called when an exception is uncaught. You can install your own terminate handler with the set_terminate function. The downside is that your terminate handler may never return; it must terminate your program with some operating system primitive. The default is just to call abort()

这篇关于C ++中的全局异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆