try and except in python 3 code example
Example 1: python try catch
try:
except ValueError:
except (BadThingError, HorrbileThingError) as e:
except:
else:
finally:
Example 2: try except python
try:
print("I will try to print this line of code")
except:
print("I will print this line of code if an error is encountered")
Example 3: catch error data with except python
import sys
try:
S = 1/0
except:
e = sys.exc_info()
print(e)
try:
S = 1/0
except ZeroDivisionError as e:
print(e)
Example 4: try except python
def sum_of(x, y):
try:
print(x + y)
except TypeError:
print("Invalid argument specified.")
Example 5: try except python
try:
print("Hi there")
except:
print("A error happened with the code above")
Example 6: python try except
try:
print("I will try to print this line of code")
except Exception as e:
print(f"Error message: {}")