Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43194

Re: newbie question about confusing exception handling in urllib

References <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com> <c395da30-c593-4aeb-960e-69bf98c31880@googlegroups.com> <51642e32$0$30003$c3e8da3$5496439d@news.astraweb.com>
Date 2013-04-10 02:23 +1000
Subject Re: newbie question about confusing exception handling in urllib
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.362.1365524611.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Apr 10, 2013 at 1:05 AM, Steven D'Aprano
<steve+comp.lang.python@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

newbie question about confusing exception handling in urllib cabbar@gmail.com - 2013-04-09 04:41 -0700
  Re: newbie question about confusing exception handling in urllib Peter Otten <__peter__@web.de> - 2013-04-09 14:19 +0200
  Re: newbie question about confusing exception handling in urllib cabbar@gmail.com - 2013-04-09 06:19 -0700
    Re: newbie question about confusing exception handling in urllib Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-09 15:05 +0000
      Re: newbie question about confusing exception handling in urllib Chris Angelico <rosuav@gmail.com> - 2013-04-10 02:23 +1000
      RE: newbie question about confusing exception handling in urllib "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2013-04-12 21:29 +0000
  Re: newbie question about confusing exception handling in urllib Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-09 10:19 -0400
  Re: newbie question about confusing exception handling in urllib Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-09 13:11 -0600

csiph-web