Is correct except ErrorA or ErrorB:
|
1 answer
To catch exceptions whose types are not bound by a common hierarchy, write their names in brackets separated by commas.
try: # ... ΠΊΠ°ΠΊΠΎΠΉ-ΡΠΎ ΠΊΠΎΠ΄ ... except (TypeError, IndexError, ZeroDivisionError) as err: # ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ° ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΡ ΡΠΈΠΏΠ° TypeError, IndexError Π»ΠΈΠ±ΠΎ ZeroDivisionError # ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΡ Π²ΡΠ΅Ρ
ΠΏΡΠΎΡΠΈΡ
ΡΠΈΠΏΠΎΠ²* Π±ΡΠ΄ΡΡ ΠΏΠ΅ΡΠ΅Π΄Π°Π½Ρ Π΄Π°Π»Π΅Π΅ ΠΏΠΎ ΠΊΠΎΠ΄Ρ * which are not derived from the above
The as err is optional, it only allows you to refer to the exception object to get additional information about the error.
A little more detail about the syntax of exceptions can be found in the built-in documentation for the pydoc except command (enter in the terminal; on systems based on Debian, you need to write pydoc3 except ). Or call the help("except") directly from Python for help.
|
except(ErrorA, ErrorB):- Igor Igoryanych