Is correct except ErrorA or ErrorB:

  • four
    except(ErrorA, ErrorB): - Igor Igoryanych

1 answer 1

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.