PY3.E0701

Bad except order

Used when except clauses are not in the correct order (from the more specific to the more generic). If you don't fix the order, some exceptions may not be caught by the most specific handler.

Noncompliant Code:

Copy
try:
    # if the line below raises TypeError then this won't reach
    # never by block with this exception and will be caught by Exception
    print(int(input()))
except Exception:
    raise
except TypeError:
    raise

Compliant Code:

Copy
try:
    print(int(input()))
except TypeError:
    raise
except Exception:
    raise

The content on this page is adapted from the Pylint User Guide, Copyright ©2003-2022, Logilab, PyCQA and contributors. All rights reserved. https://pylint.pycqa.org/en/latest/index.html#, and is used under the Python Software Foundation License Version 2. Examples, recipes, and other code in the Pylint documentation are additionally licensed under the Zero Clause BSD License.