如果我在项目中禁用C ++异常,会发生什么? [英] What exactly will happen if I disable C++ exceptions in a project?

查看:124
本文介绍了如果我在项目中禁用C ++异常,会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual C ++有一个编译器设置启用C ++异常,可以设置为否。如果我这样设置,会发生什么?我的代码从不显式抛出或捕获异常(因此第一个抛出的异常将终止程序),不依赖于堆栈解开 - 我应该期望从重新编译的程序更多的不受欢迎的行为吗?

Visual C++ has a compiler setting "Enable C++ Exceptions" which can be set to "No". What exactly will happen if I set it this way? My code never explicitly throws or catches exceptions (and therefore the first thrown exception will terminate the program anyway) and doesn't rely on stack unwinding - should I expect any more undesired behaviour from the recompiled program?

推荐答案

MSDN文档的设置解释了不同的异常模式,甚至给出了代码示例来显示不同模式之间的差异。此外,本文可能很有趣,即使它很旧。

The MSDN documentation of the setting explains the different exception modes and even gives code examples to show the difference between the different modes. Furthermore, this article might be interesting, even though it's pretty old.

底线:该选项基本上启用或禁用跟踪所有对象的生命周期。这种跟踪是必需的,因为在异常的情况下,需要调用所有正确的析构函数,堆栈必须解开,并且进行大量的清理。这种跟踪需要组织开销(=额外的代码) - 可以通过将选项设置为否来删除。

Bottom line: The option basically enables or disables the tracking of the life-spans of all your objects. Such tracking is required, because in the case of an exception, all the proper destructors need to be called, the stack has to be unwinded, and a lot of clean up is done. Such tracking requires organizational overhead (= additional code) - this can be dropped by setting the option to "No".

我没有尝试过,像你仍然可以 throw catch 异常,如果选项设置为否,但清理和解开缺少,这可能有非常糟糕的后果(不推荐)。

I haven't tried by myself, but it looks like you still can throw and catch exceptions if the option is set to "No", but the clean up and unwinding is missing, which might have very bad consequences (not recommended ;) ..

这篇关于如果我在项目中禁用C ++异常,会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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