args (exception)

The tuple of arguments an exception object was created with.

In more detail

Every exception stores the arguments passed to it in a tuple called args. Printing the exception shows str(e), which is empty for no arguments, the argument itself for one, and the whole tuple for two or more. A custom exception keeps args even when its own __init__ never calls super().

Example

try:
    raise ValueError('bad', 42)
except ValueError as e:
    print(e.args)   # ('bad', 42)

Related terms

Taught in

References

Certification courses