C ++异常处理 [英] C++ Exception handling

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

问题描述

C ++异常处理有用吗?认为这太复杂了。什么

种项目需要使用它吗?谢谢。

Is C++ Exception handling useful? think it is too complicated. What
kinds of project need to use it? Thanks.

推荐答案

在2006-03-03, ju ****** @ gmail.com < ju ****** @ gmail.com>写道:
On 2006-03-03, ju******@gmail.com <ju******@gmail.com> wrote:
C ++异常处理有用吗?认为这太复杂了。什么类型的项目需要使用它?谢谢。
Is C++ Exception handling useful? think it is too complicated. What
kinds of project need to use it? Thanks.




这个功能本身并不复杂,只是正确地使用它们才能正确使用它们。它们就像这样的单轮脚踏车。


当设计具有可能失败的结构的对象时,异常

变得非常有用。另一个选择是返回无效的对象和

希望没有人使用它们。


-

Neil Cerutti



The feature itself isn''t that complicated, it''s just using them
correctly that is hard. They are rather like a unicycle in that way.

When designing objects with contructors that might fail, exceptions
become quite useful. The other option is to return invalid objects and
hope nobody uses them.

--
Neil Cerutti


2006年3月3日09:48:15 -0800, ju ****** @ gmail.com 写道:
On 3 Mar 2006 09:48:15 -0800, ju******@gmail.com wrote:
C ++异常处理有用吗?认为这太复杂了。


异常处理与RAII(最重要的C ++习语)结合使用

大大简化了编程。在C ++中,只有当你忽略RAII并尝试在Java风格的

中使用它时,异常处理才会很复杂。

需要什么类型的项目使用它?
Is C++ Exception handling useful? think it is too complicated.
Exception handling combined with RAII (the most important C++ idiom)
greatly simplifies programming. In C++ exception handling is
complicated only if you disregard RAII and try to use it in
Java-style.
What kinds of project need to use it?




所有除了''Hello world''。


祝福,

Roland Pibinger



All except ''Hello world''.

Best wishes,
Roland Pibinger



ju ****** @ gmail.com 写道:
C ++异常处理有用吗?认为这太复杂了。什么类型的项目需要使用它?谢谢。
Is C++ Exception handling useful? think it is too complicated. What
kinds of project need to use it? Thanks.




是的,C ++异常处理机制非常有用。


这是一种处理错误的更强大的方法比起挑剔的

检查成功时返回0的函数的错误代码,以及

失败时的一些非零值。这种错误代码检查是非常繁琐的,并且模糊了你的程序逻辑。


C ++异常模型:

*析构函数是调用所有活动对象作为函数堆栈

调用unwinds。

*异常规范指定函数的异常类型

将抛出。

*终止与恢复语义。


我不认为异常处理过于复杂。你需要

理解:

*实现的语法。

*抛出异常时会发生什么。

*如何处理异常。


希望这会有所帮助...


迈克


-----

ACGNJ Java用户组
http://www.javasig.org/



Yes, the C++ exception handling mechanism is extremely useful.

It is a more robust method for handling errors than fastidiously
checking for error codes from functions that return 0 on success, and
some non-zero value on failure. This kind of error code checking is
tedious and obscures your program logic.

The C++ Exception Model:
* destructors are invoked for all live objects as the stack of function
calls "unwinds."
* exception specifications specify what type of exception(s) a function
will throw.
* termination vs. resumption semantics.

I wouldn''t consider exception handling too complicated. You need to
understand:
* the syntax to implement.
* what happens when an exception is thrown.
* how to handle the exception.

Hope this helps...

Mike

-----
ACGNJ Java Users Group
http://www.javasig.org/


这篇关于C ++异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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