蟒蛇。从多个异常中提出异常

时间:2018-02-20 11:41:35

标签: python python-3.x exception error-handling raise

我可以引发异常from另一个例外,以便提供其他信息,例如:

try:
    age = int(x)
except Exception as ex:
    raise ValueError("{} is not a valid age.".format(x)) from ex

有没有办法从多个例外来源? e.g。

try:
    age = int(x)
except Exception as ex1:
    try:
        age = date_now().year - parse_date(x).year
    except Exception as ex2:
        raise ValueError("{} is not a valid age or date.".format(x)) from ex1 + ex2

0 个答案:

没有答案
相关问题