在编译时强制异常捕获 [英] Forcing Exception Catching At Compile Time

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

问题描述




有没有办法强制对象的用户捕获

特定类型的异常?

,例如,如果异常''ExeceptionXXX''抛出

方法''​​ThrowsExceptionXXX''未被捕获,则会发出编译错误。

谢谢,

bryan



is there a way to force the user of an object to catch exceptions of
specific type?

for instance a compile error is issued if exception ''ExeceptionXXX'' thrown
by method ''ThrowsExceptionXXX'' is not caught.
thanks,
bryan

推荐答案



" Bryan Bullard" <第******************** @ sbcglobal.net>在留言新闻中写道:aj ***************** @ newssvr23.news.prodigy.co m ...

"Bryan Bullard" <th********************@sbcglobal.net> wrote in message news:aj*****************@newssvr23.news.prodigy.co m...
hi,

有没有办法强制对象的用户捕获特定类型的异常?

例如,如果异常''ExeceptionXXX''被抛出则发出编译错误/> by method''ThrowsExceptionXXX''未被捕获。


is there a way to force the user of an object to catch exceptions of
specific type?

for instance a compile error is issued if exception ''ExeceptionXXX'' thrown
by method ''ThrowsExceptionXXX'' is not caught.



无法做到这一点。例外情况不需要用于抛出它们的函数

,甚至是一级(如果是这样的话,他们会'b $ b没有什么目的,你' 我只是回来了。


No way to do that. Exceptions need not be caught in the function
that throws them, or even one level up (if that were the case, they''d
have little purpose, you''d just return instead).




" Ron Natalie" < ro*@sensor.com>在留言中写道

新闻:3f *********************** @ news.newshosting.co m ...


ron-


不,不在抛出它们的函数中。我不确定我的问题是否清楚。


i想知道是否有办法迫使编译器检查是否有

异常可通过相关方法抛出。如果对该方法的调用

不在try / catch块中,则会产生编译时错误。


类似于java。


谢谢,

bryan


"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

ron-

no, not in the function that throws them. i''m not sure if my question was
clear.

i want to know if there is a way to force the compiler to check to see if an
exception is throwable by the method in question. if a call to that method
is not in a try/catch block a compile time error is produced.

similar to java.

thanks,
bryan


Bryan Bullard <第******************** @ sbcglobal.net>在消息中写道

"Bryan Bullard" <th********************@sbcglobal.net> wrote in message



新闻:aj ***************** @ newssvr23.news.prodigy.co m ...


news:aj*****************@newssvr23.news.prodigy.co m...



有没有办法强制对象的用户捕获特定类型的异常?
<例如,如果未捕获由方法''ThrowsExceptionXXX'抛出的异常''ExeceptionXXX''
,则会发出编译错误。


is there a way to force the user of an object to catch exceptions of
specific type?

for instance a compile error is issued if exception ''ExeceptionXXX'' thrown by method ''ThrowsExceptionXXX'' is not caught.


无法做到这一点。例外情况不需要在引发它们的函数中被捕获,或者甚至一级上升(如果是这样的话,它们没有什么目的,你只会返回)。 br />


No way to do that. Exceptions need not be caught in the function
that throws them, or even one level up (if that were the case, they''d
have little purpose, you''d just return instead).



在文章< Zz ***************** @newssvr23.news.prodigy .COM> ,Bryan Bullard写道:
In article <Zz*****************@newssvr23.news.prodigy.com> , Bryan Bullard wrote:

Ron Natalie < ro*@sensor.com>在消息中写道
新闻:3f *********************** @ news.newshosting.co m ...
ron-

不,不在抛出它们的函数中。我不确定我的问题是否清楚。

我想知道是否有办法强制编译器检查
异常是否可抛出通过有问题的方法。如果调用该方法
不在try / catch块中,则会产生编译时错误。

类似于java。

"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

ron-

no, not in the function that throws them. i''m not sure if my question was
clear.

i want to know if there is a way to force the compiler to check to see if an
exception is throwable by the method in question. if a call to that method
is not in a try/catch block a compile time error is produced.

similar to java.




C ++没有检查异常。它有例外规格,它与b $ b不是一回事。如果您愿意,可以谷歌搜索此主题。在C ++社区中有一种广泛的感觉,即在C ++中实现的异常规范并不是很有帮助。


干杯,

-

Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/


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

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