[Python] Avoiding "Too broad exception clause" warning in PyCharm

Discussão em 'Python' iniciado por Stack, Junho 4, 2025.

  1. Stack

    Stack Membro Participativo

    I'm writing an exception clause at the top level of a script, and I just want it to log whatever errors occur. Annoyingly, PyCharm complains if I just catch Exception.

    import logging

    logging.basicConfig()

    try:
    raise RuntimeError('Bad stuff happened.')
    except Exception: # <= causes warning: Too broad exception clause
    logging.error('Failed.', exc_info=True)


    Is there something wrong with this handler? If not, how can I tell PyCharm to shut up about it?

    Continue reading...

Compartilhe esta Página