Reputation: 331
import traceback
def func():
try:
-- do something --
except:
traceback.print_exc()
For this code
pylint reporting error: bare-except No exception type(s) specified , W0702, Occurs when an except clause doesn't specify exceptions type to catch.
Now, if I want all exceptions to be captured without pylint error. Is there a way.
Please help.
Thanks
Upvotes: 8
Views: 15911
Reputation: 6109
You can locally disable pylint if you are sure of what you are doing (as you seem to be here)
With the following comment
# pylint: disable=W0702
If my memory serves me right, you should use it this way
import traceback
def func():
try:
-- do something --
except: # pylint: disable=W0702
traceback.print_exc()
As Jack mentionned below, it is probably better to be more explicit about the warning:
except: # pylint: disable=bare-except
Upvotes: 10
Reputation: 10613
I prefer using this more meaningful style:
def func():
try:
-- do something --
except: # pylint: disable=bare-except
traceback.print_exc()
Upvotes: 17