我可以随时确定我抓到了什么吗? [英] Can I always determine what I catch?

查看:51
本文介绍了我可以随时确定我抓到了什么吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我理解正确,我无法保证我可以确定作为例外抛出的简单类实例的类型

除非我明确地按名称捕获

。 (没有虚拟函数的非派生类没有rtti)

也就是说,没有办法做类似的事情:

尝试{

funct_from_3rd_party();

}

catch(...){

std:err<< extract_name()<< std :: endl;

}


这是对的吗?我是否有办法访问

catch(...)中捕获的对象?

-

STH
哈顿定律:只有一个不可侵犯的法律

KDevelop: http://www.kdevelop.org SuSE: http:/ /www.suse.com

Mozilla: http:// www.mozilla.org

If I understand correctly, I have no assurance that I can determine the type
of a simple class instance thrown as an exception unless I explicitly catch
it by name. (non-derived classes having no virtual funcitons have no rtti)
That is, there is no way to do something like:
try{
funct_from_3rd_party();
}
catch(...){
std:err << extract_name() << std::endl;
}

Is this correct? Do I even have a way to access the object caught in a
catch(...)?
--
STH
Hatton''s Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org

推荐答案

" Steven T. Hatton" <苏****** @ setidava.kushan.aa>写道...
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote...
如果我理解正确,我无法保证我可以确定作为异常抛出的一个简单类实例的
类型,除非我明确
抓住它名称。 (没有虚拟函数的非派生类没有
rtti)也就是说,没有办法做类似的事情:
尝试{
funct_from_3rd_party();
}
catch(...){
标准:错误<< extract_name()<< std :: endl;
}

这是对的吗?我是否有办法访问
catch(...)中捕获的对象?
If I understand correctly, I have no assurance that I can determine the type of a simple class instance thrown as an exception unless I explicitly catch it by name. (non-derived classes having no virtual funcitons have no rtti) That is, there is no way to do something like:
try{
funct_from_3rd_party();
}
catch(...){
std:err << extract_name() << std::endl;
}

Is this correct? Do I even have a way to access the object caught in a
catch(...)?




不以任何标准方式。如果你想捕捉特定的东西,比如

a后代的std :: exception,那么通过引用捕获''std :: exception'',然后你至少有b $ b打电话给''what()''希望他们管理好

来正确实施它。


OTOH,如果他们(第三方)根本没有记录他们的例外情况,那里有
无法知道他们扔什么以及什么时候扔。联系他们并索取一些

种文件(或至少他们有'抛出''

表达式和陈述的源代码)。


Victor



Not in any standard way. If you want to catch something particular, like
a descendant of std::exception, then catch ''std::exception'' by reference,
then you at least have a shot at calling ''what()'' in hope that they managed
to implement it correctly.

OTOH, if they (the 3rd party) didn''t document their exceptions at all, there
is no way to know what they throw and when. Contact them and ask for some
kind of documentation (or at least the source code where they have ''throw''
expressions and statements).

Victor


* Steven T. Hatton:
* Steven T. Hatton:
如果我理解正确,我无法保证我能确定一个简单类实例的类型
作为异常抛出,除非我明确地按名称捕获它。 (没有虚函数的非派生类没有rtti)
也就是说,没有办法做这样的事情:
尝试{
funct_from_3rd_party();
}
catch(...){
标准:错误<< extract_name()<< std :: endl;
}

这是对的吗?


No.


我是否有办法访问catch(...)中捕获的对象?
If I understand correctly, I have no assurance that I can determine the type
of a simple class instance thrown as an exception unless I explicitly catch
it by name. (non-derived classes having no virtual funcitons have no rtti)
That is, there is no way to do something like:
try{
funct_from_3rd_party();
}
catch(...){
std:err << extract_name() << std::endl;
}

Is this correct?
No.

Do I even have a way to access the object caught in a catch(...)?




是的。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

问:什么是最烦人的事情usenet和电子邮件?



Yes.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Alf P. Steinbach写道:
Alf P. Steinbach wrote:
* Steven T. Hatton:
* Steven T. Hatton:
如果我理解正确,我无法保证我可以确定作为例外抛出的简单类实例的类型,除非我明确地按名称捕获它。 (没有虚拟函数的非派生类没有
rtti)也就是说,没有办法做类似的事情:
尝试{
funct_from_3rd_party();
}
catch(...){
标准:错误<< extract_name()<< std :: endl;
}
这是正确的吗?
If I understand correctly, I have no assurance that I can determine the
type of a simple class instance thrown as an exception unless I
explicitly catch
it by name. (non-derived classes having no virtual funcitons have no
rtti) That is, there is no way to do something like:
try{
funct_from_3rd_party();
}
catch(...){
std:err << extract_name() << std::endl;
}

Is this correct?



没有。



No.

我是否有办法访问捕获的对象(...)?
Do I even have a way to access the object caught in a catch(...)?



是的。



Yes.



我相信你拼错了RTFM? ;)我会再看一遍。

-

STH

哈顿定律:只有一个不可侵犯的法则 ;

KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com

Mozilla : http://www.mozilla.org


I believe you misspelled RTFM? ;) I''ll look again.
--
STH
Hatton''s Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org


这篇关于我可以随时确定我抓到了什么吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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