Python-Ref > Basic usage > Exceptions > An important fact about exceptions

Klíčová slova
Knihovní funkce

An important fact about exceptions

Once an exception is thrown, following python commands are skipped until an except clause is found. Then the code continues after this clause. Therefore the code between the place where the exception occured and the corresponding except clause is ignored. This is one reason why it is wise to put as short code inside one try clause as possible.
Zdroj: (
  1   try:
  2       print "lets go"
  3       print 1/0
  4       # luckily for us, the following code in never evaluated
  5       print "something nasty about your boss."
  6       # the following line would in fact throw an error as well (NameError)
  7       format_your_harddrive( 'now')
  8   except ZeroDivisionError:
  9       print "sorry, you cannot divide by zero :("
lets go
sorry, you cannot divide by zero :(
Doba běhu: 21.5 ms