Reputation: 63
I am trying to catch the error that stops the execution of my python script. But I don't want to catch all the errors or exception because some of them are not affecting the success of my scripts they are just guidance or console Info. I only want to catch and stock in a variable the error that cause my python script to stop. Thanks by advance
Upvotes: 0
Views: 734
Reputation: 543
Here's a small example on how to catch a specific error. Let's say you would want to check if a ZeroDivisionError
is raised:
a = 3
b = 0
try:
_ = a/b
except ZeroDivisionError as e:
print(str(e))
Running the above code snippet would result in:
division by zero
Upvotes: 1