Skip to content

Instantly share code, notes, and snippets.

@troygnichols
Created August 25, 2014 01:41
Show Gist options
  • Save troygnichols/e304e64b7ed0269d3ef8 to your computer and use it in GitHub Desktop.
Save troygnichols/e304e64b7ed0269d3ef8 to your computer and use it in GitHub Desktop.
Example of exception handling logic in python
#!/usr/bin/env python
def get_user_input():
user_input = raw_input("Type in a number: ")
print ("You typed: %s") % user_input
convert_user_input_to_number(user_input)
def convert_user_input_to_number(user_input):
try:
user_input_as_integer = int(user_input)
print ("Looks like you typed a valid number. Good job, buddy!")
except:
print ("That's not a number, but okay.")
get_user_input()
get_user_input()
print ("Done with this interesting program now. Bye!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment