.. _try-except-raise: try-except-raise / W0706 ======================== **Message emitted:** ``The except handler raises immediately`` **Description:** *Used when an except handler uses raise as its first or only operator. This is useless because it raises back the exception immediately. Remove the raise operator or the entire try-except-raise block!* **Problematic code:** .. literalinclude:: /data/messages/t/try-except-raise/bad.py :language: python **Correct code:** ``remove_try_except.py``: .. literalinclude:: /data/messages/t/try-except-raise/good/remove_try_except.py :language: python ``specialized_exception.py``: .. literalinclude:: /data/messages/t/try-except-raise/good/specialized_exception.py :language: python **Additional details:** There is a legitimate use case for re-raising immediately. E.g. with the following inheritance tree:: +-- ArithmeticError +-- FloatingPointError +-- OverflowError +-- ZeroDivisionError The following code shows valid case for re-raising exception immediately:: def execute_calculation(a, b): try: return some_calculation(a, b) except ZeroDivisionError: raise except ArithmeticError: return float('nan') The pylint is able to detect this case and does not produce error. Created by the `exceptions `__ checker.