异常处理 - “尝试”的重要性 [英] Exception handling -- the significance of "try"

查看:84
本文介绍了异常处理 - “尝试”的重要性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几本书和网站中的异常处理,但是我们仍然对基本点感到困惑。


我理解试试.. 。抓住语法。


但是,我已经看到了使用throw的例子,其中throw-command是

不在try-block中。


投掷试块后的意义有什么区别?
扔在试块外?


保罗爱泼斯坦

I have read about exception handling in a few books and websites but am
still confused on a basic point.

I understand the try ... catch syntax.

However, I have seen examples of using throw where the throw-command is
not in a try-block.

What is the difference in meaning between throwing in a try block and
throwing outside a try block?

Paul Epstein

推荐答案

pa * *********@att.net 写道:
pa**********@att.net wrote:

我已阅读过几本书和网站中的异常处理但是

仍然在基本点上感到困惑。


我理解try ... catch语法。


但是,我看过使用throw的例子,其中throw-command是

不在try-block中。


投掷之间的意义有什么区别在一个试块中和
扔出一个试块?
I have read about exception handling in a few books and websites but am
still confused on a basic point.

I understand the try ... catch syntax.

However, I have seen examples of using throw where the throw-command is
not in a try-block.

What is the difference in meaning between throwing in a try block and
throwing outside a try block?



没有区别。请注意,您不需要在

中捕获异常函数。您还可以在另一个函数中捕获它,即

调用它。

There is no difference. Note that you don''t need to catch an exception in
the function that threw it. You can also catch it in another function that
calls it.


在文章< ee ****** *******@news.t-online.com>,

Rolf Magnus< ra ****** @ t-online.dewrote:
In article <ee*************@news.t-online.com>,
Rolf Magnus <ra******@t-online.dewrote:
pa**********@att.net 写道:
pa**********@att.net wrote:

我已经阅读了几本书籍和网站中的异常处理,但是我们仍然对基本点感到困惑。


我理解try ... catch语法。


但是,我看过使用throw的例子,其中throw-command是

不在试用版块中。


投掷试块和

扔在试块外的意义有什么区别?
I have read about exception handling in a few books and websites but am
still confused on a basic point.

I understand the try ... catch syntax.

However, I have seen examples of using throw where the throw-command is
not in a try-block.

What is the difference in meaning between throwing in a try block and
throwing outside a try block?



没有区别。请注意,您不需要在

中捕获异常函数。您还可以在另一个函数中捕获它,即
调用它。


There is no difference. Note that you don''t need to catch an exception in
the function that threw it. You can also catch it in another function that
calls it.



或者没有全部捕获,在这种情况下,它被一些低级运行时代码所捕获()例程被调用。

Or not catch it all, in which case it''s caught by some low-level runtime
code that ran before your main() routine was called.


Roy Smith写道:
Roy Smith wrote:

抛出try块和

抛出try块之间有什么区别?
What is the difference in meaning between throwing in a try block and
throwing outside a try block?


没有区别。请注意,您不需要在抛出它的函数中捕获异常。您也可以在另一个调用它的函数中捕获它。


There is no difference. Note that you don''t need to catch an exception in
the function that threw it. You can also catch it in another function
that calls it.



或者没有全部捕获,在这种情况下,它被一些低级运行时代码所捕获()例程被调用。


Or not catch it all, in which case it''s caught by some low-level runtime
code that ran before your main() routine was called.



实际上,调用了std :: terminate(),你可以为它定义自己的

处理程序。默认处理程序只调用std :: abort()。

Actually, std::terminate() is called, for which you can define your own
handler. The default handler simply calls std::abort().


这篇关于异常处理 - “尝试”的重要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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