How to prevent “too broad exception” in this case?

后端 未结 6 2018
情话喂你
情话喂你 2021-02-05 00:00

I have a list of functions that may fail and, if one fails, I don\'t want the script to stop, but to continue with next function.

I am executing it with something like th

6条回答
  •  甜味超标
    2021-02-05 00:48

    From issue PY-9715 on yourtrack.jetbrains.com:

    From pep-0348:

    BaseException

    The superclass that all exceptions must inherit from. It's name was chosen to reflect that it is at the base of the exception hierarchy while being an exception itself. "Raisable" was considered as a name, it was passed on because its name did not properly reflect the fact that it is an exception itself.

    Direct inheritance of BaseException is not expected, and will be discouraged for the general case. Most user-defined exceptions should inherit from Exception instead. This allows catching Exception to continue to work in the common case of catching all exceptions that should be caught. Direct inheritance of BaseException should only be done in cases where an entirely new category of exception is desired.

    But, for cases where all exceptions should be caught blindly, except BaseException will work.

提交回复
热议问题