how to raise exception in python code example
Example 1: how to print error in try except python
try:
# some code
except Exception as e:
print("ERROR : "+str(e))
Example 2: how to raise a error in python
# You can raise a error in python by using the raise keyword
raise Exception("A error occured!")
Example 3: throwing an exception python
raise Exception("message")
Example 4: raise exception in python
raise Exception('I know Python!') # Don't! If you catch, likely to hide bugs.
Example 5: exception pyton print
except Exception as e: print(e)
Example 6: try catch in python
try:
print("try to run this block")
except:
print("run this bock if there was error in earlier block")