banana_99
banana_99

Reputation: 641

W0703: Catching too general exception Exception (broad-except)

I'm using pylint to review one of my .py scripts and the below warning shows:

W0703: Catching too general exception Exception (broad-except)

This is an extract of the code.

try:
    # Execute function1
    function1()
    logger.info('Function 1 successfully executed')
    
except Exception as e:
    send_mail_error(str(e))
    logger.error(str(e))

I would like to understand what is pylint suggesting here in order to improve it.

Upvotes: 2

Views: 8334

Answers (1)

marcin
marcin

Reputation: 567

It is good practice to catch specific exception, read here.

In your case you want to log unknown exception and send email. In such case I am using SMTPHandler and custom sys.excepthook - like this.

Upvotes: 2

Related Questions