<p dir="ltr"><br>
On Jul 5, 2013 12:12 AM, "Lele Gaifax" <<a href="mailto:lele@metapensiero.it">lele@metapensiero.it</a>> wrote:<br>
><br>
> Νίκος Gr33k <<a href="mailto:nikos@superhost.gr">nikos@superhost.gr</a>> writes:<br>
><br>
> > try:<br>
> >       host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]<br>
> > except Exception as e:<br>
> >       host = "Reverse DNS Failed"<br>
> ><br>
> > How can the above code not be able to reeverse dns any more and it<br>
> > falls back to  the failed string?<br>
><br>
> The only way to know is actually printing out the exception, either to<br>
> stderr, or better using the logging facility, as I suggested.<br>
><br>
> FYI, your code above is (almost) exactly equivalent to the simpler<br>
><br>
>     try:<br>
>         host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]<br>
>     except:<br>
>         host = "Reverse DNS Failed"<br>
><br>
> ciao, lele.<br>
> </p>
<p dir="ltr">They aren't equivalent. "except Exception" won't catch KeyboardInterrupt or SystemExit or a few others that you really don't want to catch in a generic error handler. You should almost never have a bare except.<br>

</p>