python - 如果您的库与错误的 Python 版本一起使用,应该引发什么适当的内置异常?

标签 python python-3.x exception version

我有一个作为 .py 文件分发的简单库。如果库是从 Python 2 而不是 Python 3 调用的,我想抛出一个异常:

def _check_version():
    if sys.version_info < (3,):
        raise _____Exception('This library depends on Python 3 strings. Please ensure you are using Python 3 instead of Python 2')

我应该引发什么内置异常? (我如何填写上面的空白?)我能在 builtin Exceptions 中找到最接近的异常。是 NotImplementedError。 DeprecationWarning 感觉很接近,但在这种情况下异常(exception)更合适。

最佳答案

我会使用 RuntimeError为了这;没有更具体的异常(exception)。

关于python - 如果您的库与错误的 Python 版本一起使用,应该引发什么适当的内置异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46164094/

相关文章:

java - Android 未处理的异常错误

.net - 为什么.net 异常没有被捕获?

python - 在不可迭代函数上执行进度条 - Python

python - 如何在 Python 中组合重叠的矩形

python-3.x - 否定 np.where 中的 np.isnan

python - 我可以向 SSLSocket 提供可接受的主机名列表吗?

python - 如何将字符串转换为属性?

python - 如何引发 python 异常并包含 Sentry 的附加数据?

python - 使用 Python 的请求登录 FT.com

python - 接收来自特定源的UDP数据包