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


Groups > comp.lang.python > #79956

Re: When using a decorator exceptions raised reference the decorator not the function

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=373e29111=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:not': 0.03; 'preferably': 0.05; 'decorator': 0.09; 'exception,': 0.09; 'subject:using': 0.09; 'try:': 0.09; 'python': 0.11; '2.7': 0.14; 'called,': 0.16; 'raised.': 0.16; 'subject: \n ': 0.16; 'subject:raised': 0.16; 'exception': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'code,': 0.22; 'creating': 0.23; 'example.': 0.24; 'replace': 0.24; 'logging': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'raise': 0.29; "i'm": 0.30; 'exceptions': 0.31; 'extract': 0.31; 'origin': 0.31; 'raised': 0.31; 'class': 0.32; '-----': 0.33; 'subject:the': 0.34; 'except': 0.35; 'something': 0.35; 'email addr:python.org': 0.37; 'thank': 0.38; 'to:addr :python-list': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'you.': 0.62; 'show': 0.63; 'information': 0.63; 're:': 0.63; 'received:194': 0.64; 'email name:python-list': 0.65; 'notice:': 0.67; 'person,': 0.68; 'privileged.': 0.69; 'disclose': 0.74; 'bare': 0.84; 'medium.': 0.91
X-IronPort-AV E=Sophos;i="5.07,285,1413237600"; d="scan'208";a="3529006"
Date Thu, 30 Oct 2014 14:24:16 +0100 (CET)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To python-list@python.org
In-Reply-To <m2tbtm$obv$2@ger.gmane.org>
Subject Re: When using a decorator exceptions raised reference the decorator not the function
MIME-Version 1.0
X-Mailer Zimbra 7.2.7_GA_2942 (ZimbraWebClient - GC37 (Linux)/7.2.7_GA_2942)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15323.1414675466.18130.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414675466 news.xs4all.nl 2851 [2001:888:2000:d::a6]:42615
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79956

Show key headers only | View raw


----- Original Message -----
> From: "Peter Otten" <__peter__@web.de>
> To: python-list@python.org
> Sent: Thursday, 30 October, 2014 1:45:42 PM
> Subject: Re: When using a decorator exceptions raised reference the decorator not the function
> 
> Néstor Boscán wrote:
> 
> > I'm using Python 2.7 and I'm creating a class decorator that
> > extract
> > information from exceptions for logging purposes.
> > 
> > Everytime an exception is raised from the original function and I
> > extract
> > the origin of the exception with sys.exc_info() I get a reference
> > to the
> > line in the decorator where the function is called, not the line of
> > the
> > original function where the exception was raised.
> > 
> > Any ideas?
> 
> Please show us the code, preferably as a small self-contained
> example. Thank
> you.

+1 show us your decorator.

if you did something like:

try:

except Exception, e:
  # do something
  raise e


Then replace "raise e" by a bare "raise"


JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

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


Thread

Re: When using a decorator exceptions raised reference the decorator not the function Jean-Michel Pichavant <jeanmichel@sequans.com> - 2014-10-30 14:24 +0100

csiph-web