Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #15471
| Date | 2011-11-08 18:15 +0100 |
|---|---|
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
| Subject | Re: Help catching error message |
| References | <8629ed5b-a657-4bda-9930-a0571279f4d6@p20g2000prm.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2545.1320772544.27778.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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