What is the best way to collect errors and send a summary?
<p>I have a script executing several independent functions in turn. I would like to collect the errors/exceptions happening along the way, in order to send an email with a summary of the errors.</p>

<p>What is the best way to raise these errors/exceptions and collect them, while allowing the script to complete and go through all the steps? They are independent, so it does not matter if one crashes. The remaining ones can still run.</p>

<pre><code>def step_1():
    # Code that can raise errors/exceptions

def step_2():
    # Code that can raise errors/exceptions

def step_3():
    # Code that can raise errors/exceptions

def main():
    step_1()
    step_2()
    step_3()

    send_email_with_collected_errors()

if '__name__' == '__main__':
    main()
</code></pre>

<p>Should I wrap each step in a try..except block in the main() function? Should I use a decorator on each step function, in addition to an error collector?</p>

<p>use simple <code>try</code> <code>except</code> statements and do logging for the exceptions that would be standard way to collect all your errors.</p>

python