On Wed, Apr 10, 2013 at 1:05 AM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > One exception to this rule (no pun intended) is that sometimes you want > to hide the details of unexpected tracebacks from your users. In that > case, it may be acceptable to wrap your application's main function in a > try block, catch any unexpected exceptions, log the exception, and then > quietly exit with a short, non-threatening error message that won't scare > the civilians
This is important to some types of security concern, too; for instance, if I'm running a web server, I probably don't want to leak details of exceptions and tracebacks to a potential attacker. Same again: catch the exception, log it, return simple error message; additionally, you can return that message as an HTTP response rather than simply bombing the web server. But again, a bare except should almost always be logging its exceptions. True story, though not in Python: After taking over the code of an ex-coworker, I was trying to fix some crazy problems. Everything I did seemed to kinda-work, but nothing properly worked. Trying to clean up the code to comply with "use strict" mode (which will tell you what language this is, and it isn't Perl) was a matter of blundering about in the dark. Turned out there was an event handler somewhere that buried the *entire file full of code* behind a callback that caught and suppressed everything. Gee, thanks. Web browsers these days are pretty good at reporting exceptions - we were mainly using Chrome's inbuilt Firebug-equivalent - but our brilliant coworker saw fit to hide them all. Exceptions are a huge boon. ChrisA -- http://mail.python.org/mailman/listinfo/python-list