2

I want to use Argument of an Exception to show additional information while an error occur in my code. Here is my code.

ArgumentOfAnException.py

from pip._vendor.distlib.compat import raw_input

def to_celsius(f):
    try:
        c = (f-32)*5/9;
        return c;
    except ValueError, Argument:
        print("The argumet doesn't contain number\n", Argument);
        return;

f = raw_input("Enter temperature in *F : ");
print("Temperature in Celsius : ", to_celsius(float(f)));
print("Thank you...");

Here I use Argument variable to display additional information when error occur in my code but after running the program there will show a syntax error in the console output and the error is like

File "F:\Document\Files\Coding\Java Eclipse\Python Project\First Project\src\Error\ArgumentOfAnException.py", line 7
    except ValueError, Argument:
                     ^
SyntaxError: invalid syntax
falsetru
  • 336,967
  • 57
  • 673
  • 597
Aditya
  • 1,164
  • 6
  • 18
  • 27

1 Answers1

4

It seems like you're using python 3.x.

Use following syntax (using as):

except ValueError as Argument:

Reference: try statement - Python 3 documentation

falsetru
  • 336,967
  • 57
  • 673
  • 597