为何选择“类别例外”不赞成? [英] Why "class exceptions" are not deprecated?

查看:52
本文介绍了为何选择“类别例外”不赞成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)从2.4.2文档:

raise语句有两种新的有效(语义)形式:

raise class,instance

引发实例


2)在python中:

raise NameError
Traceback(最近一次调用最后一次):

文件"< stdin>",第1行,在?

NameError help(NameError)
模块异常中的NameError类帮助:... raise 0



Traceback(最近一次调用最后一次):

文件"< stdin>",第1行,在?

TypeError:例外必须是类,实例或字符串

(不建议使用),而不是我

nt


因此,如果它是文档中的错误,则应予以纠正。否则,应该弃用提高类的
(恕我直言!)。提高班级是否会产生
sence?至于我,我找不到任何有用的案例。

解决方案

Gregory Petrosyan写道:
< blockquote class =post_quotes> 1)从2.4.2文档:
raise语句有两种新的有效(语义)形式:
raise class,instance
raise instance

2)在python中:

引发NameError Traceback(最近一次调用最后一次):
文件"< stdin>",第1行,在?NameError错误帮助(NameError)类ID中的帮助模块异常中的NameError:... raise 0

Traceback(最近一次调用最后一次):
文件"< stdin> ",第1行,在?
TypeError:异常必须是类,实例或字符串
(已弃用),不是我


所以,如果它文档中存在错误,应予以纠正。否则,
(恕我直言!)提升课程应该被弃用。




可能是教程作者希望你阅读第8章

在您阅读第9章之前,并使用了new表示没有描述的形式:

http://docs.python.org/tut/node10.html

提升课程是否有意义?至于我,我找不到任何有用的案例。




,如语言参考中所述,

筹集班级





筹集班级相同()


< / F>


感谢您的回答。但是明确比隐含更好呢?


"第一个引发名称引发异常的参数。

可选的第二个参数指定异常的参数。

或者,上面的内容可以写为raise

NameError(''HiThere '')。这两种形式都可以正常使用,但后者似乎有一种增长的风格偏好。


是否有任何弃用计划?


1) From 2.4.2 documentation:
There are two new valid (semantic) forms for the raise statement:
raise Class, instance
raise instance

2) In python:

raise NameError Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError help(NameError) Help on class NameError in module exceptions: ... raise 0


Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: exceptions must be classes, instances, or strings
(deprecated), not i
nt

So, if it''s a bug in documentation, it should be corrected. Otherwise,
(IMHO!) raising classes should be deprecated. Does raising class make
sence? As for me, I can''t find any usefull case for it.

解决方案

Gregory Petrosyan wrote:

1) From 2.4.2 documentation:
There are two new valid (semantic) forms for the raise statement:
raise Class, instance
raise instance

2) In python:

raise NameError Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError help(NameError) Help on class NameError in module exceptions: ... raise 0

Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: exceptions must be classes, instances, or strings
(deprecated), not i
nt

So, if it''s a bug in documentation, it should be corrected. Otherwise,
(IMHO!) raising classes should be deprecated.



it could be that the tutorial author expected you to read chapter 8
before you read chapter 9, and used "new" to mean forms that hadn''t
already been described:

http://docs.python.org/tut/node10.html
Does raising class make sence? As for me, I can''t find any usefull
case for it.



as explained in the language reference,

raise Class

is the same thing as

raise Class()

</F>


Thanks for answer. But what about "Explicit is better than implicit"?


"The first argument to raise names the exception to be raised. The
optional second argument specifies the exception''s argument.
Alternatively, the above could be written as raise
NameError(''HiThere''). Either form works fine, but there seems to be a
growing stylistic preference for the latter."

Are there any deprecation plans?


这篇关于为何选择“类别例外”不赞成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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