Pass variable to an exception?
<p>I am trying to learn Python and I want to know if it is possible to pass a variable to an <code>Exception</code>? This is the code I have:</p>

<pre><code>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")
</code></pre>

<p>I want to pass <code>staffId</code> to the exception so that I can print something like: </p>

<p>print("There was a problem converting data for staff Id: ", staffId)</p>

<p>I tried this with no success: <a href="https://stackoverflow.com/questions/6626816/how-to-pass-a-variable-to-an-exception-when-raised-and-retrieve-it-when-excepted">How to pass a variable to an exception when raised and retrieve it when excepted?</a></p>