赶上(...) [英] catch (...)

查看:66
本文介绍了赶上(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在catch all语句块中时,是否有任何方法可以检索错误信息(例如,来自''global''

或系统范围内)错误对象?


有时它无法帮助,当一些奇怪的事情发生并且错误

在堆栈中传播 - 一直到''一刀切''br / >
catch(...)声明。如果有一种方法可以找到什么样的东西发生了什么事情并引导我们到那一点,那将是有用的。

Is there any way of retrievieng error information (say, from a ''global''
or system wide) error object - when you are in a catch all statement block?

Sometimes it cannot be helped, when something quirky happens and errors
are propagated up the stack - all the way to the ''one size fits all''
catch (...) statement. It would be useful if there is a way of finding
what srewy thing happened and led us to that point.

推荐答案

位字节写道:
有什么方法可以检索错误信息(例如,从全局或系统范围)错误对象 - 当你在捕获所有语句块?

有时它无法帮助,当一些奇怪的事情发生并且错误从堆栈中传播 - 一直到'一个尺寸适合所有''
catch(...)声明。如果有一种方法可以找到发生了什么事情并引导我们到那一点,这将是有用的。
Is there any way of retrievieng error information (say, from a ''global''
or system wide) error object - when you are in a catch all statement block?

Sometimes it cannot be helped, when something quirky happens and errors
are propagated up the stack - all the way to the ''one size fits all''
catch (...) statement. It would be useful if there is a way of finding
what srewy thing happened and led us to that point.




当然,如果那个全局错误对象是在异常之前正确设置

被抛出(参见errno)。你不会从

异常本身获得任何信息(例如,它的类型或来自

std :: exception :: what()的消息)因为

a catch-all中没有特定的例外。


< OT>某些平台(特别是微软)抛出异常其他

错误,例如由任意指针引起的访问违规。

(Microsoft称这种结构异常处理(SEH)。请参阅
http://www.boost.org/more/error_handling.html 如何减轻影响SEH''

干扰调试器。)如果你指的是这个,那么你需要在新闻组中询问你的平台。< b $ b ; / OT>


干杯! --M



Sure, if that global error object was properly set before the exception
was thrown (cf. errno). You won''t get any information out of the
exception itself (e.g., it''s type or a message from
std::exception::what()) since there is no specific exception caught in
a catch-all.

<OT>Some platforms (notably Microsoft) throw "exceptions" for other
errors such as access violations resulting from a wayward pointer.
(Microsoft calls this structure exception handling (SEH). See
http://www.boost.org/more/error_handling.html on how to mitigate SEH''s
interference with the debugger.) If that''s what you''re referring to,
you should ask in a newsgroup for your platform.</OT>

Cheers! --M


* mlimber:
* mlimber:
位字节写道:
有没有办法检索错误信息(例如,来自全局或系统范围)错误对象 - 当您处于catch all语句块中时?

有时它无法帮助古怪的事情和错误
传播到堆栈 - 一直到''一个尺寸适合所有''
catch(...)声明。如果有一种方法可以找到发生的事情并引导我们到那一点,那将是有用的。
Is there any way of retrievieng error information (say, from a ''global''
or system wide) error object - when you are in a catch all statement block?

Sometimes it cannot be helped, when something quirky happens and errors
are propagated up the stack - all the way to the ''one size fits all''
catch (...) statement. It would be useful if there is a way of finding
what srewy thing happened and led us to that point.



当然,如果在全局错误对象之前正确设置了异常
被抛出(参见errno)。你不会从
异常中获取任何信息(例如,它的类型或来自
std :: exception :: what()的消息)因为没有特定的异常被捕获总而言之。



Sure, if that global error object was properly set before the exception
was thrown (cf. errno). You won''t get any information out of the
exception itself (e.g., it''s type or a message from
std::exception::what()) since there is no specific exception caught in
a catch-all.




相反,有一个特定的例外被捕获。


尝试


#include< cstddef>

#include< stdexcept>

#include< iostream> ;

#include< ostream>


int main()

{

try

{

throw std :: runtime_error(" Indeed");

}

catch(... )

{

试试

{

throw;

}

catch(std :: exception const& x)

{

std :: cerr<< "!" << x.what()<< std :: endl;

}

catch(...)

{

std :: cerr< ;< !未知异常 << std :: endl;

}

返回EXIT_FAILURE;

}

}


模数错字,当然;另外,不能使用像VC6这样的旧编译器。


内部try-catch可以移动到一个单独的函数。


-

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

问:为什么这么糟糕?

A:热门发布。

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



On the contrary, there is a specific exception caught in a catch-all.

Try

#include <cstddef>
#include <stdexcept>
#include <iostream>
#include <ostream>

int main()
{
try
{
throw std::runtime_error( "Indeed" );
}
catch( ... )
{
try
{
throw;
}
catch( std::exception const& x )
{
std::cerr << "!" << x.what() << std::endl;
}
catch( ... )
{
std::cerr << "!Unknown exception" << std::endl;
}
return EXIT_FAILURE;
}
}

Modulo typos, of course; also, won''t work with older compilers like VC6.

The inner try-catch can be moved to a separate function.

--
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?


位字节写道:
Bit byte wrote:
当您处于catch all语句中时,是否有任何方法可以检索错误信息(例如,来自全局或系统范围的错误对象) br?>块?
Is there any way of retrievieng error information (say, from a ''global''
or system wide) error object - when you are in a catch all statement
block?




No.


正如Alf指出的,你仍然可以找到一种方法来访问这个东西抛出 - 如果

你知道它的类型。在这种情况下,这就足够了:


try {allMyProgram(); }

catch(std :: exception& e)

{

cout<<无论如何;

}

catch(...)

{

cout<<无论如何;

}


现在问题是如何最大限度地减少未处理的异常

对客户的影响。您的程序应该编写一个日志文件,可选择

记录每个程序活动。当程序错误时,将其日志文件

并编写一个产生类似日志文件的验收测试。


当您接近问题时,请使用调试器一个[off-topic]功能,以确定每个''throw''语句的
断点,找出它是哪一个。


如果使用MS Windows ,检查他们的新闻组,了解如何捕获他们的操作系统抛出的特殊结构化异常。这些是不同的,但是

catch(...)可以捕获它们。


-

Phlip
http://www.greencheese.org/ZeekLand < - 不是博客!!!



No.

As Alf pointed out, you can still find a way to access the thing thrown - if
you know its type. In which case, this would suffice:

try { allMyProgram(); }
catch( std::exception & e )
{
cout << whatever;
}
catch(...)
{
cout << whatever;
}

So now the question is how to minimize the impact of an unhandled exception
on your customers. Your program should write a log file that optionally
records each program activity. When the program faults take its log file
and write an acceptance test that produces a similar log file.

As you near the problem, use a debugger with an [off-topic] feature to
breakpoint each ''throw'' statement, to find out which one it was.

If you use MS Windows, check with their newsgroups to learn how to catch the
special structured exceptions their OS throws. These are different, but
catch(...) can catch them.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


这篇关于赶上(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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