1try:
2 someFunction()
3except Exception as ex:
4 template = "An exception of type {0} occurred. Arguments:\n{1!r}"
5 message = template.format(type(ex).__name__, ex.args)
6 print (message)
1import sys
2
3try:
4 f = open('myfile.txt')
5 s = f.readline()
6 i = int(s.strip())
7except OSError as err:
8 print("OS error: {0}".format(err))
9except ValueError:
10 print("Could not convert data to an integer.")
11except:
12 print("Unexpected error:", sys.exc_info()[0])
13 raise
1try:
2 val = 1/0
3except Exception as e:
4 raise Exception('ZeroDivisionError')
1try:
2 print("I will try to print this line of code")
3except Exception as e:
4 print(f"Error message: {}")