0
What does it mean?
except Exception as ex: ...
4 Respostas
+ 2
It's called catching an exception.
Every exception in Python inherits from the base Exception class.
except Exception as ex:
means you are catching whatever Exception was raised by the try block and renaming it as ex. You can rename it anything.
except Exception as e:
except Exception as err:
Then you can print it, log it or handle different exceptions in whatever way you want.
+ 2
try:
print(undefinedVariable)
except Exception as somevar:
print(somevar)
Output is the exception: name undefinedVariable is not declared
+ 1
https://docs.python.org/3/tutorial/errors.html
8.3 might be, what you are looking for
+ 1
Bob_Li thx