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


Groups > comp.lang.python > #15472

Re: Help catching error message

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=286f65499=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'string.': 0.04; 'python': 0.08; 'ioerror:': 0.09; 'subject:error': 0.10; 'exception': 0.12; 'def': 0.14; 'cc:addr:python-list': 0.15; 'this:': 0.15; '[errno': 0.16; 'file"': 0.16; 'py3': 0.16; 'received:192.168.200': 0.16; 'wsgi.': 0.16; 'subject:Help': 0.17; 'wrote:': 0.18; 'apache': 0.19; 'cc:no real name:2**0': 0.21; '2.5,': 0.23; 'clause': 0.23; 'name?': 0.23; 'header:In-Reply-To:1': 0.23; 'string': 0.23; 'changed': 0.24; 'variable': 0.24; "i'm": 0.26; 'looks': 0.28; 'cc:addr:python.org': 0.29; 'cc:addr:gmail.com': 0.30; 'error': 0.31; 'hi,': 0.31; "can't": 0.32; "isn't": 0.32; 'there': 0.33; 'it?': 0.33; 'header:User-Agent:1': 0.33; 'elegant': 0.34; 'try:': 0.34; 'unless': 0.35; 'cc:2**1': 0.36; 'none': 0.36; 'but': 0.37; 'using': 0.37; 'received:192': 0.38; 'returned': 0.38; 'except': 0.39; "there's": 0.39; 'subject:: ': 0.39; 'more': 0.60; 'success': 0.60; 'header:Received:6': 0.60; 'back': 0.62; 'works,': 0.68; 'gone': 0.68; 'imagine': 0.71; 'failure': 0.74; 'exc:': 0.84
X-IronPort-AV E=Sophos;i="4.69,477,1315173600"; d="scan'208";a="2374775"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Tue, 08 Nov 2011 18:24:30 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To 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>
In-Reply-To <4EB963BC.7080506@sequans.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list@python.org, Gnarlodious <gnarlodious@gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2546.1320773067.27778.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1320773067 news.xs4all.nl 6927 [2001:888:2000:d::a6]:39961
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15472

Show key headers only | 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