有没有用于C ++投掷装饰? [英] Is there any use for C++ throw decoration?

查看:119
本文介绍了有没有用于C ++投掷装饰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以统一的方式开始使用C ++异常,现在我希望编译器(g ++)检查没有异常泄漏。 throw 装饰应该这样做,就像 const 对于类方法的常量一样。

I've started using C++ exceptions in a uniform manner, and now I'd like the compiler (g++) to check that there are no "exception leaks". The throw decoration should do this, like const does for constness of class methods.

嗯,没有。

使用 throw 仍然是纪录片,但可能如果其他人认为一个函数不能抛出其他文档中列出的异常,那么即使是危险的误导。

Using throw is still documentary, but may even be dangerously misleading if others think a function cannot throw other exceptions than those listed in its documentation.

可以说g ++可以被劝说更加严格的检查,即真正确保以 throw()作为装饰的功能永远不会抛出任何东西。

Can g++ somehow be persuaded to be more strict on its throw-checking, i.e. really making sure a function decorated as throw() will never-ever throw anything.

编辑:
发现这个问题广泛地处理这个问题。 p>

Found this question handling the subject widely.

推荐答案

它不检查编译时间,但符合条件的编译器应确保运行时。

It doesn't check compile-time, but a conforming compiler should ensure it at run-time.

如果某个函数抛出任何异常声明,C ++运行时应该调用std :: unexpected,如果我记得ctly。

If a function throws anything outside of its throw-declaration, the C++ run-time should call std::unexpected, if I recall correctly.

这篇关于有没有用于C ++投掷装饰?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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