关于python:将变量传递给异常?

Pass variable to an exception?

我正在学习python,想知道是否可以将变量传递给Exception?这是我的代码:

1
2
3
4
5
6
7
8
9
10
try:
    staffId = int(row['staffId'])
    openingSalary = int(row['initialSalary'])
    monthsWorked = float(row['monthsWorked'])
except CutomException:
    pass

class CustomException(ValueError): # raised if data conversion fails
    def __init__(self):
        print("There was a problem converting data")

我想把staffId传给例外,这样我就可以打印如下内容:

print("为员工ID转换数据时出现问题:",staff id)

我尝试过但没有成功:如何在引发异常时将变量传递给异常,并在异常时检索它?


(P)The custom exception will need to be EDOCX1 universal 0'd conditionally by the EDOCX1 universal 2 common block to include the EDOCX1 universal 3.作为一个例子,当"EDOCX1"是一个"EDOCX1"的英文5,而不是一个"EDOCX1"的英文6。(p)字母名称


(P)The caller of the exception,e.g.the one that EDOCX1 universifical 0 nabel exception will have to pass an argument to the constructor.(p)字母名称