C ++ throw装饰有什么用处吗? [英] Is there any use for C++ throw decoration?

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

问题描述

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



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



可以说服g ++更严格的抛出检查,即真正确保装饰为 throw()的函数永远不会发生任何事情。



编辑:
找到此问题广泛处理主题。 p>

解决方案

它不检查编译时,但一个合格的编译器应该在运行时确保它。



如果一个函数抛出了它的throw声明之外的任何东西,C ++运行时应该调用std :: unexpected,如果我记得正确。


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.

Well, it doesn't.

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.

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.

Edit: Found this question handling the subject widely.

解决方案

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

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

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

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