Error handling with @parallel decorator

Ankur Agrawal ankur.cse at gmail.com
Tue Jan 19 10:01:43 EST 2016


Thanks a lot Steven for your reply. I got the issue, it was my own
FabricException class, when I started using Exception then I could catch
the exception successfully and then I got the type of exception as well by
using your suggested type(err). Your code snippet did help me to find the
issue sooner.

Thanks,
Ankur

On Sun, Jan 17, 2016 at 11:16 PM Steven D'Aprano <
steve+comp.lang.python at pearwood.info> wrote:

> On Monday 18 January 2016 17:15, Ankur Agrawal wrote:
>
> > I am trying to catch Abort exception. When I use fabric's run(...)
> method,
> > the host it tries to connect is not available and so it aborts with
> > connect time out exception. I am not able to catch it. Following is a two
> > different ways of code snippet-
> > First I try following  -
> >
> > class FabricException(Exception):
> >     pass
> >
> > with settings(abort_exception = FabricException):
> >
> > try:
> >     output = run(command)
> > except FabricException:
> >     print 'inside exception'
> >     LOG.debug("inside exception")
> >
> > It didn't go in exception block. Instead it threw -
> > NetworkError: Timed out trying to connect to
> pqaltsnas300.corp.intuit.net
> > (tried 1 time)
> > Aborting.
> > SystemExit: 1
>
> Are you sure that the exception is being raised where you think it is being
> raised? You think that it is being raised by run(command), but it is
> possible that the exception is occurring somewhere else?
>
> Don't catch the exception at all, and read the *entire* traceback. It will
> show you what line is raising the error.
>
> Then, surround that line with:
>
> try:
>     the line that fails
> except Exception as err:
>     print err
>     print type(err)
>     LOG.debug(err)
>     raise
>
> This will tell you exactly what the exception type actually is. Perhaps you
> are trying to catch the wrong thing.
>
> VERY IMPORTANT: catching all exceptions in this way should nearly always
> only be used for debugging purposes. Don't do that in production.
>
> https://realpython.com/blog/python/the-most-diabolical-python-antipattern/
>
>
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list