Q:

Pass variable to an exception?

I am trying to learn Python and I want to know if it is possible to pass a variable to an Exception? This is the code I have:
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")

I want to pass staffId to the exception so that I can print something like: 
print("There was a problem converting data for staff Id: ", staffId)
I tried this with no success: How to pass a variable to an exception when raised and retrieve it when excepted?

A:

The caller of the exception, e.g. the one that raise exception will have to pass an argument to the constructor.
class CustomException(ValueError): # raised if data conversion fails
    def __init__(self, message):
        self.message = message;
        print("There was a problem converting data")

try:
    try:
        staffId = int(row['staffId'])
        openingSalary = int(row['initialSalary'])
        monthsWorked = float(row['monthsWorked'])
    except ValueError as e:
        raise CustomException(e);
except CustomException:
    pass

