Printing out actual error message for ValueError
How can I actually print out the ValueError's message after I catch it?
If I type except ValueError, err:
into my code instead of except ValueError as err:
, I get the error SyntaxError: invalid syntax
.
Solution 1:
try:
...
except ValueError as e:
print(e)
Solution 2:
Python 3 requires casting the exception to string before printing:
try:
...
except ValueError as error:
print(str(error))