i

Python Programming

The argument of Exception

Exception may have an argument, which is value gives additional information about  the problem. The contents of argument vary by exception. You capture exception's argument by supplying variable in except clause follows:

try:

   You do operations here

    except ExceptionType Argument:

   You can print value of Argument here...

If you write code to handle single exception, you can have variable follow the name of  exception in except statement. If you are trapping multiple exceptions you have a variable follow the tuple of exception.

This variable receives value of the exception mostly containing cause of exception. The variable can receive single value or multiple values in form of tuple. This tuple usually contains error string, error number, and an error location.

Example

Following is example of a single exception:

Live Demo

Output:

The argument don’contain numbers

invalid litral for int() with base 10: 'xyz'