try:f = open('myfile.txt')s = f.readline()i = int(s.strip())except IOError as (errno, strerror):print("I/O error({0}): {1}".format(errno, strerror))except ValueError:print("Could not convert data to an integer.")except:print("Unexpected error:", sys.exc_info()[0])raise
try:print "Performing an action which may throw an exception."except Exception, error:print "An exception was thrown!"print str(error)else:print "Everything looks great!"finally:print "Finally is called directly after executing the try statement whether an exception is thrown or not."
from google.api_core.exceptions import ServiceUnavailable, RetryError
for i in range(10):try:print("do something")
except ValueError:print("I know this might happen for now at times! skipping this and continuing with my loop"
except ServiceUnavailable:print("our connection to a service (e.g. logging) of gcp has failed")print("initializing the cloud logger again and try continuing ...")
except RetryError:print("gcp connection retry failed. breaking the loop. try again later!)break