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


Groups > comp.lang.python > #75623

Re: try/exception - error block

From Peter Otten <__peter__@web.de>
Subject Re: try/exception - error block
Followup-To gmane.comp.python.general
Date 2014-08-04 00:20 +0200
Organization None
References <CAP16ngohN8fNsX9CDPuRoXTuq3N89MWDfxqgHK-td-VzztErTw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.12598.1407104469.18130.python-list@python.org> (permalink)

Followups directed to: gmane.comp.python.general

Show all headers | View raw


bruce wrote:

> Hi.
> 
> I have a long running process, it generates calls to a separate py
> app. The py app appears to generate errors, as indicated in the
> /var/log/messages file for the abrtd daemon.. The errors are
> intermittent.
> 
> So, to quickly capture all possible exceptions/errors, I decided to
> wrap the entire "main" block of the test py func in a try/exception
> block.
> 
> This didn't work, as I'm not getting any output in the err file
> generated in the exception block.
> 
> I'm posting the test code I'm using. Pointers/comments would be
> helpful/useful.

>   try:

[...]

>   except Exception, e:
>     print e
>     print "pycolFac1 - error!! \n";
>     name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE)
>     name=name.communicate()[0].strip()
>     name=name.replace("-","_")
>     name2="/home/ihubuser/parseErrTest/pp_"+name+".dat"
>     ofile1=open(name2,"w+")
>     ofile1.write(e)

You can't write exceptions to the file, just strings. Try

      print >> ofile1, e

or
      ofile1.write(str(e) + "\n")

instead of the above line.

>     ofile1.write(aaa)
>     ofile1.close()
> 
>     sys.exit()

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


Thread

Re: try/exception - error block Peter Otten <__peter__@web.de> - 2014-08-04 00:20 +0200

csiph-web