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


Groups > comp.lang.python > #15472

Re: Help catching error message

Date 2011-11-08 18:24 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: Help catching error message
References <8629ed5b-a657-4bda-9930-a0571279f4d6@p20g2000prm.googlegroups.com> <4EB963BC.7080506@sequans.com>
Newsgroups comp.lang.python
Message-ID <mailman.2546.1320773067.27778.python-list@python.org> (permalink)

Show all headers | View raw


Jean-Michel Pichavant wrote:
> Gnarlodious wrote:
>> What I say is this:
>>
>> def SaveEvents(self,events):
>>    try:
>>       plistlib.writePlist(events, self.path+'/Data/Events.plist') #
>> None if OK
>>    except IOError:
>>       return "IOError: [Errno 13] Apache can't write Events.plist
>> file"
>>
>> Note that success returns"None" while failure returns a string.
>>
>> I catch the error like this:
>>
>> errorStatus=Data.Dict.SaveEvents(Data.Plist.Events)
>> if errorStatus: content=errorStatus
>>
>> It works, but isn there a more elegant way to do it? As in, one line?
>> I can imagine if success returned nothing then content would remain
>> unchanged. Isn't there a built-in way to send an error string back and
>> then catch it as a variable name?
>>
>> This is Py3 inside WSGI.
>>
>> -- Gnarlie
>>   
> Hi,
>
> There's no need to rephrase an exception unless you want to *add* 
> information.
>
> def saveEvents(self,events):
>    plistlib.writePlist(events, self.path+'/Data/Events.plist')
> try:      Data.Dict.SaveEvents(Data.Plist.Events)
> except IOError, exc: # i'm using python 2.5, this except clause may 
> have changed in py3
>    content = str(exc)
>
> JM
>
looks like for whatever reason the formating has gone crazy.
http://www.copypastecode.com/100088/

jm

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


Thread

Help catching error message Gnarlodious <gnarlodious@gmail.com> - 2011-11-08 05:20 -0800
  Re: Help catching error message Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-11-08 18:15 +0100
  Re: Help catching error message Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-11-08 18:24 +0100
  Re: Help catching error message Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-08 22:16 +0000
    Re: Help catching error message Gnarlodious <gnarlodious@gmail.com> - 2011-11-08 17:48 -0800
      Re: Help catching error message Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-09 02:57 +0000

csiph-web