Why is "except ValueError:"/"except ValueError as ve:" invalid syntax
I have searched and I keep ending up with nothing. On some sites it says "except ValueError as ve:" is correct but on others it says "except ValueError:" is correct. neither work here. I have no idea what to do so I guessed this was the last option. Hopefully I get an answer.
Try and except works like this:
try: do this except: if error do this
You can get the exact error that was thrown like this:
try: print(1+1) except Exception as e: print(str(e))
What this does is trigger when any exception occurs, and then store that exception in a variable e, sort like opening a file:
with open() as file:
The ValueError one is just one that only happens when a ValueError accurs, I don't know all the different types of errors but I'm sure you can just google it.