ruff/docs/rules/raise_vanilla_class.md
2023-02-08 11:04:31 -05:00

826 B

raise-vanilla-class (TRY002)

Derived from the tryceratops linter.

What it does

Checks for bare exceptions.

Why is this bad?

It's hard to capture generic exceptions making it hard for handling specific scenarios.

Example

def main_function():
    if not cond:
        raise Exception()
def consumer_func():
    try:
        do_step()
         prepare()
        main_function()
    except Exception:
        logger.error("I have no idea what went wrong!!")

How it should be

def main_function():
    if not cond:
        raise CustomException()
def consumer_func():
    try:
        do_step()
        prepare()
        main_function()
    except CustomException:
        logger.error("Main function failed")
    except Exception:
        logger.error("I have no idea what went wrong!!")