异常规范不是为我运行的吗? [英] Exception specification is not running for me?

查看:86
本文介绍了异常规范不是为我运行的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



提前谢谢.
我试图从我的功能之一中限制异常对象的数据类型.但无法做到.
根据我的理解,以下代码不应引发"char"类型异常.但是我的程序仍然无法限制"char"类型的抛出吗?
我正在使用Visual Studio2008.

请参见下面的代码:

Hi,

Thanks in advance.
I am trying to restrict exception object data-types from in one of my function. But not able to do it.
As per my understanding, below code should not throw "char" type exception. But still my program is unable to restrict "char" type throw?
I am using visual studio 2008.

Please see the code below:

void FuncThrow(int choice)throw(int, float)
{
switch(choice)
{
case 1: throw 10;
break;
case 2: throw 10.0f;
break;
case 3: throw ''x'';
break;
default:
break;
}
}
int main()
{
try
{
FuncThrow(3);
}

catch(int)
{
cout << "Exception from int"<<endl;
}
catch(float)
{
cout << "Exception from float"<<endl;
}
catch(char)
{
cout << "Exception from character"<<endl;
}


}

推荐答案

Microsoft的编译器不支持异常规范,但throw()除外.

来源
Microsoft''s compiler doesn''t support exception specification except throw().

Source


要抛出的类型的限制将滥用结构异常处理.在任何情况下都不会有所帮助.

-SA
The restriction of the type to be thrown would abuse the structural exception handling. There are no situations where is can be helpful.

—SA


请参见 http://msdn.microsoft.com/en-us/library/wfa0edys.aspx [
See http://msdn.microsoft.com/en-us/library/wfa0edys.aspx[^]

for more information on Visual C++ implementation.


这篇关于异常规范不是为我运行的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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