News for hackers. Stuff that matters.
Re:Handling exceptions in Python like a pro by Animats on Thursday May 20, 2021 @12:13AM (#27217301)

    try:
        ...
    except Exception as e:
Don't catch Exception at a low level. Catch OSError, which now includes EnvironmentError and IOError. This should cover all the things that can occur for external reasons. If you get some unexpected error such as a SyntaxError or TypeError, for example, that indicates a bug in the program. At the outermost level, catch Exception, and log a bug with a backtrace if an unhandled exception reaches that level.

An exception is not an error code.

There are no comments on this comment yet.