Handling such exceptions requires the use of except Exception or
except BaseException. These will capture almost any raised exception,
including failed assertions, division by zero, and more.
Prefer to raise your own exception, or a more specific built-in
exception, so that you can avoid over-capturing exceptions that you
don't intend to handle.
defmain_function():ifnotcond:raiseCustomException()defconsumer_func():try:do_step()prepare()main_function()exceptCustomException:logger.error("Main function failed")exceptException:logger.error("Oops")