0

What does it mean?

except Exception as ex: ...

21st Mar 2022, 7:31 PM
😎_M_😎
😎_M_😎 - avatar
4 odpowiedzi
+ 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.
21st Mar 2022, 9:40 PM
Bob_Li
Bob_Li - avatar
+ 2
try: print(undefinedVariable) except Exception as somevar: print(somevar) Output is the exception: name undefinedVariable is not declared
21st Mar 2022, 9:05 PM
Fu Foy
Fu Foy - avatar
+ 1
https://docs.python.org/3/tutorial/errors.html 8.3 might be, what you are looking for
21st Mar 2022, 9:00 PM
Fu Foy
Fu Foy - avatar
+ 1
Bob_Li thx
22nd Mar 2022, 11:31 AM
😎_M_😎
😎_M_😎 - avatar