Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python try except finally

'''
In python, you can use try, except and finally to catch errors to keep
running your code even when you run into an error.

try:
	# insert code
except SpecificError:
	# code that will run if the code in 'try' doesn't work
finally:
	# always runs this code, error or not
'''

try:
  myVar = 10 / 0 # runs into an error
except ZeroDivisionError as error:
  print(error) # prints error to user
finally:
  print('Finished try, except, finally') # always prints

  
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #python #finally
ADD COMMENT
Topic
Name
4+6 =