Antoine BATTAGLIOTTI
Antoine BATTAGLIOTTI

Reputation: 63

Catch the error which stops the execution of my Python script

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

Answers (2)

Vishnu Dasu
Vishnu Dasu

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

horseshoe
horseshoe

Reputation: 1477

Did you try:

try:
   code where my error occurs
except:
   pass

Upvotes: 1

Related Questions