user44756
0
Q:

python try catch all

try:
  # Dangerous stuff
except ValueError:
  # If you use try, at least 1 except block is mandatory!
  # Handle it somehow / ignore
except (BadThingError, HorrbileThingError) as e:
  # Hande it differently
except:
  # This will catch every exception.
else:
  # Else block is not mandatory.
  # Dangerous stuff ended with no exception
finally:
  # Finally block is not mandatory.
  # This will ALWAYS happen after the above blocks.
11
   1 import sys
   2 try:
   3   untrusted.execute()
   4 except: # catch *all* exceptions
   5   e = sys.exc_info()[0]
   6   write_to_page( "<p>Error: %s</p>" % e )
4
try:
    raise Exception("Oh no! An error happened!")
except Exception as err:
    print("An error was handled")
finally:
  	print("This runs either way.")
0

New to Communities?

Join the community