python except else code example
Example 1: exception pyton print
except Exception as e: print(e)
Example 2: raise python
raise(Exception("Put whatever you want here!"))
raise(TypeError)
Example 3: python try else
try:
print('Test')
except (SyntaxError, IndexError) as E:
print('Synthax or index error !')
except:
print('Other error !')
else:
print('No error')
finally:
print('Done')
print('Anything else')
Example 4: python try else
try:
a=2*3
except TypeError:
print("Exception raised")
else:
print("Everything is ok.")
Example 5: try except python
def sum_of(x, y):
try:
print(x + y)
except TypeError:
print("Invalid argument specified.")