强制异常处理 [英] Forcing exception handling

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

问题描述

hi


在java中我发现当一个方法在定义中有一个throws子句时,

调用者必须处理方法抛出的异常他们是

来电或前进通过指定一个抛出

子句来调用者的例外。


c ++中是否有类似的机制?我想强迫开发人员为我的类库的方法可能抛出的所有可能的异常写入

处理程序。

谢谢

bruno

解决方案

在星期五,2003年7月25日23:30:55 +0200,Ritz,Bruno, <峰; br ******** @ gmx.ch>写道:

在java中我发现当一个方法在定义中有一个throws子句时,
调用者必须要么处理它们所采用的方法抛出的异常
呼叫或转发通过指定一个throws
子句来调用者的例外。

在c ++中是否有类似的机制?


不。有异常规范,但默认

是一个异常不匹配时调用std :: unexpected,

和std :: unexpected默认调用std ::如果异常规范list,则终止或

(非常不清楚的语言
这里的标准是
)std :: bad_exception,扔掉它。大多数经验丰富的C ++程序员认为空的异常

规范,可能只是可能的规范

允许std :: exception,作为唯一有用的规范。


i想强迫开发人员为我的类库的方法可能抛出的所有可能的异常编写处理程序。




你真是邪恶! < g>


你能给出一个方法的具体例子,抛出一些

不同的异常,其中这些_must_由
$ b处理$ b来电和不同的时装?




" Ritz,Bruno"写道:

[...]

在c ++中是否有类似的机制?


Nope。

i想强迫开发人员为我的类库的方法抛出所有可能的异常编写
处理程序。



你为什么要强迫任何人做(或不做)任何事情?如果

你想要的就是行使一些权威,那就是孩子们所需要的。你有孩子吗?


问候,

亚历山大。


P.S.好吧,

http ://groups.google.com/groups?selm ... 00006%40web.de

(主题:Re:C ++异常处理)

< a rel =nofollowhref =http://groups.google.com/groups?threadm=3C729687.3A8A462%40web.detarget =_ blank> http://groups.google.com/groups?thre ... 8A462%40web.de

(主题:回复:本周大师#82:解决方案)




" Alf P. Steinbach"写道:

[...]

在这里的标准中)std :: bad_exception,抛出它。大多数有经验的C ++程序员都会考虑空的异常
规范,可能只是可能的规范
允许std :: exception作为唯一有用的规范。




是的。但是大多数MOST经验丰富的C ++程序员认为当前的C ++异常处理存在严重的问题,因为缺少强制性* 2阶段*处理和完全被破坏的ES的


http:// google。 com / groups?threadm = 3EB ... E66C4%40web.de

(主题:__属性__((清理(函数))与try / finally)
http://google.com/groups?threadm=3EC ... 0B266%40web.de

(主题:异常处理......是时候修改标准了)

http://google.com/groups?threadm=3EE...7A32D% 40web.de

(主题:std0X :: expected_exception< T>())

http://google.com/groups?threadm=ubr...consulting.com

(主题:Re:std0X :: expected_exception< T>()[repost])


问候,

亚历山大。


hi

in java i found that when a method has a throws clause in the definition,
callers must either handle the exceptions thrown by the method they are
calling or "forward" the exception to the caller by specifying a throws
clause as well.

is there a similar machanism in c++? i want to force a developer to write
handlers for all possible exceptions a method of my class library can throw.
thanks
bruno

解决方案

On Fri, 25 Jul 2003 23:30:55 +0200, "Ritz, Bruno" <br********@gmx.ch> wrote:

in java i found that when a method has a throws clause in the definition,
callers must either handle the exceptions thrown by the method they are
calling or "forward" the exception to the caller by specifying a throws
clause as well.

is there a similar machanism in c++?
Nope. There are exception specifications, but the default
is a call to std::unexpected when an exception doesn''t match,
and std::unexpected defaults to calling std::terminate or,
if the exception specification "lists" (very unclear language
in the standard here) std::bad_exception, throwing that. Most
experienced C++ programmers regard the empty exception
specification, and possibly but just possibly the specification
allowing std::exception, as the only useful specification(s).

i want to force a developer to write handlers for all possible
exceptions a method of my class library can throw.



You''re EVIL! <g>

Could you give a concrete example of method throwing some
different exceptions, where these _must_ be handled by the
caller and in different fashions?



"Ritz, Bruno" wrote:
[...]

is there a similar machanism in c++?
Nope.
i want to force a developer to write
handlers for all possible exceptions a method of my class library can throw.



And why do you want to force anyone to do (or not do) anything? If
all you want is just to exercise some authority, well, that''s what
kids are for. Do you have kids?

regards,
alexander.

P.S. Ah well,

http://groups.google.com/groups?selm...00006%40web.de
(Subject: Re: C++ exception handling)

http://groups.google.com/groups?thre...8A462%40web.de
(Subject: Re: Guru of the Week #82: Solution)



"Alf P. Steinbach" wrote:
[...]

in the standard here) std::bad_exception, throwing that. Most
experienced C++ programmers regard the empty exception
specification, and possibly but just possibly the specification
allowing std::exception, as the only useful specification(s).



Yeah. But most MOST experienced C++ programmers think that there are
serious problems with the current C++ exception handling due to lack
of mandatory *2-phase* processing and totaly busted ESes.

http://google.com/groups?threadm=3EB...E66C4%40web.de
(Subject: __attribute__((cleanup(function)) versus try/finally)

http://google.com/groups?threadm=3EC...0B266%40web.de
(Subject: Exception handling... it''s time to fix the standard)

http://google.com/groups?threadm=3EE...7A32D%40web.de
(Subject: std0X::expected_exception<T>())

http://google.com/groups?threadm=ubr...consulting.com
(Subject: Re: std0X::expected_exception<T>() [repost])

regards,
alexander.


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

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