![](/img/trans.png)
[英]Where can I find documentation for possible raised Exceptions for existing Python3 API's?
[英]Where can I find a list of possible exceptions in Python?
我知道为什么在Python中,尝试try..except块不尝试处理特定异常是一个坏主意。 但我无法找出在哪里可以找到任何特定库,命令或方法可能发生的异常的列表。
例如,我目前正在使用以下解码语句:
in_file = in_file.decode(encoding="ISO-8859-1") # Turn data from unicode to ascii
我怎么知道可能引发什么异常? 从广义上讲,我应该在哪里寻找此类信息?
谢谢
库文档的“ 内置例外”部分列出了内置例外 。 将字节解码为Unicode会抛出UnicodeDecodeError
异常 。
您还需要检查文档以获取要调用的方法。 您在这里调用bytes.decode()
:
错误的默认值为
'strict'
,这意味着编码错误会引发UnicodeError
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.