7
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

sinoroc
  • 18,409
  • 2
  • 39
  • 70
sanapala mohanarao
  • 321
  • 1
  • 2
  • 16

2 Answers2

16

I prefer using this more meaningful style:

def func():
    try:
        -- do something --
    except: # pylint: disable=bare-except
        traceback.print_exc()
Jack
  • 10,313
  • 15
  • 75
  • 118
10

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
BlueSheepToken
  • 5,751
  • 3
  • 17
  • 42