Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'bug': 0.02; 'subject:module': 0.04; 'value,': 0.04; 'completeness': 0.05; 'parameter': 0.05; 'herein': 0.07; 'raises': 0.07; 'exceptions': 0.09; 'pm,': 0.11; 'exception': 0.12; 'def': 0.13; 'message-----': 0.14; 'wrote:': 0.14; '712': 0.16; 'a()': 0.16; 'affiliates,': 0.16; 'blah': 0.16; 'currencies': 0.16; 'opened,': 0.16; 'otoh,': 0.16; 'received:155.180': 0.16; 'received:155.180.234': 0.16; 'received:159.53': 0.16; 'received:169.70': 0.16; 'received:169.70.190': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'solicitation': 0.16; 'unhandled': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wednesday,': 0.16; 'developer': 0.16; 'wondering': 0.19; 'to:2**1': 0.20; '(which': 0.21; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'right,': 0.22; 'applicable,': 0.23; 'module,': 0.23; 'fix': 0.24; 'reflect': 0.24; 'calling': 0.25; 'received:169': 0.25; 'received:169.254': 0.25; 'script': 0.26; "i'm": 0.26; 'url:mailman': 0.27; 'function': 0.27; 'raise': 0.29; 'error': 0.29; 'functions.': 0.29; 'annoying': 0.31; 'chase': 0.31; 'received:155': 0.31; 'received:159': 0.31; 'received:169.254.1': 0.31; 'actual': 0.31; 'format.': 0.31; 'to:addr:python-list': 0.32; 'thank': 0.32; 'url:listinfo': 0.33; '(including': 0.33; 'legally': 0.33; 'subject:': 0.33; 'things': 0.33; 'module': 0.33; 'phone:': 0.33; 'sometimes': 0.33; 'change': 0.34; 'accepted': 0.35; 'force': 0.35; 'purposes': 0.35; 'arising': 0.35; 'occurs': 0.35; 'try:': 0.35; 'too': 0.36; 'doing': 0.36; 'disclosure': 0.36; 'none': 0.36; 'charset:us- ascii': 0.36; 'problems': 0.37; 'data': 0.37; 'two': 0.37; 'some': 0.37; 'agreed': 0.37; 'refer': 0.37; 'should': 0.37; 'url:python': 0.37; 'skip:- 10': 0.37; 'accuracy': 0.38; 'andrew': 0.38; 'but': 0.38; 'url:org': 0.38; 'sent:': 0.39; 'affect': 0.39; 'errors': 0.39; 'under': 0.39; 'comments': 0.39; 'to:addr:python.org': 0.39; 'could': 0.39; 'where': 0.39; 'from:': 0.39; 'how': 0.39; 'except': 0.39; 'would': 0.40; 'necessarily': 0.40; 'street': 0.40; 'contained': 0.40; 'might': 0.40; 'co.,': 0.60; 'simple': 0.60; 'learn': 0.60; 'transaction.': 0.60; 'virus': 0.61; 'subject': 0.61; 'you.': 0.61; '2011': 0.62; 'free': 0.62; 'market': 0.63; 'legal': 0.64; 'direction.': 0.65; 'harder': 0.65; 'law.': 0.65; 'contact': 0.65; 'relating': 0.68; 'heavy': 0.69; 'below,': 0.71; 'hand,': 0.72; 'offer': 0.72; 'sale': 0.74; 'investment': 0.77; '11,': 0.77; 'bank': 0.78; 'purchase': 0.80; 'affiliates.': 0.84; 'defect': 0.84; 'prices,': 0.84; 'subject:handle': 0.84; 'mistakes': 0.91; 'instrument': 0.95; 'notice.': 0.95 X-DKIM: Sendmail DKIM Filter v2.5.6 sf1.jpmchase.com p4BIq5mP016703 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=jpmchase.com; s=smtpout; t=1305139925; bh=zyCPRhiYtzJIBQxOFakYnvsHj60ynKEjCHMlQBk M3gc=; h=From:To:Date:Subject:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=i0meZbaSUYQ iUcuSiExtdX7k7E53+oMmodnrUaCOWQiZNwALHgy5BnHf90grWpW8xBTNlCNnrEMMcE IHxrOODCo1KSI39qbbfVRYUF/oN19OWBTW+Bl2iU9JK/4wniIn+/Xw0fGq/vWjcyYDi MmfcZfm1Y2JHy8N7iXmRNGUn7I= From: "Prasad, Ramit" To: "'Andrew Berg'" , "'python-list@python.org'" Date: Wed, 11 May 2011 14:50:00 -0400 Subject: RE: Proper way to handle errors in a module Thread-Topic: Proper way to handle errors in a module Thread-Index: AcwQCv+BwGTlb6sARmS5amk8zLXoFgAALeVg References: <4DCAC78E.1000901@gmail.com> <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> <4DCAD20F.4010206@gmail.com> In-Reply-To: <4DCAD20F.4010206@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305141269 news.xs4all.nl 81482 [::ffff:82.94.164.166]:58966 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5157 The simple but code heavy system is to create two functions=2E One that rai= ses an error and one that returns None or something that is mutually agreed= to be invalid=2E You can even get away with one of them doing the actual = work and the other one just as a wrapper=2E I feel too lazy to fix the mist= akes below, but you get the idea=2E=0D=0A=0D=0A Def a():=0D=0A Blahblah=0D= =0A Raise SomeError=0D=0A=0D=0ADef b():=0D=0A Try:=0D=0A A()=0D=0A Except = SomeError:=0D=0A Return blah=0D=0A=0D=0A=0D=0ARamit=0D=0A=0D=0A=0D=0A=0D= =0ARamit Prasad | JPMorgan Chase Investment Bank | Currencies Technology=0D= =0A712 Main Street | Houston, TX 77002=0D=0Awork phone: 713 - 216 - 5423=0D= =0A=0D=0A=0D=0A-----Original Message-----=0D=0AFrom: python-list-bounces+ra= mit=2Eprasad=3Djpmchase=2Ecom@python=2Eorg [mailto:python-list-bounces+rami= t=2Eprasad=3Djpmchase=2Ecom@python=2Eorg] On Behalf Of Andrew Berg=0D=0ASen= t: Wednesday, May 11, 2011 1:15 PM=0D=0ATo: python-list@python=2Eorg=0D=0AS= ubject: Re: Proper way to handle errors in a module=0D=0A=0D=0AOn 2011=2E05= =2E11 12:57 PM, Patty wrote:=0D=0A> Hi Andrew -=0D=0A>=0D=0A> Sometimes you= want an exception come up and then use that information to =0D=0A> take yo= ur=0D=0A> program in some direction=2E=0D=0ARight, but I'm wondering how I = should handle errors in a module, where=0D=0Adifferent people will want the= ir programs to do different things when an=0D=0Aerror occurs in a function = or method from my module (which is not=0D=0Anecessarily because of a bug in= my module - the calling script could=0D=0Asend a bad parameter or some sys= tem configuration could prevent the=0D=0Afunction from doing something)=2E = On one hand, I could let almost all=0D=0Aexceptions go unhandled and have t= he calling script handle them=2E This=0D=0Awould force the developer of the= calling script to learn all the=0D=0Aexceptions that my module could raise= (which could be really annoying if=0D=0AI have custom exceptions for probl= ems that don't otherwise raise an=0D=0Aexception)=2E OTOH, I could handle a= ll the exceptions and return None or=0D=0Asome default value, but that woul= d make it harder for the developer to=0D=0Amake the script react appropriat= ely=2E=0D=0A-- =0D=0Ahttp://mail=2Epython=2Eorg/mailman/listinfo/python-lis= t=0D=0AThis communication is for informational purposes only=2E It is not= =0D=0Aintended as an offer or solicitation for the purchase or sale of=0D= =0Aany financial instrument or as an official confirmation of any=0D=0Atran= saction=2E All market prices, data and other information are not=0D=0Awarra= nted as to completeness or accuracy and are subject to change=0D=0Awithout = notice=2E Any comments or statements made herein do not=0D=0Anecessarily re= flect those of JPMorgan Chase & Co=2E, its subsidiaries=0D=0Aand affiliates= =2E=0D=0A=0D=0AThis transmission may contain information that is privileged= ,=0D=0Aconfidential, legally privileged, and/or exempt from disclosure=0D= =0Aunder applicable law=2E If you are not the intended recipient, you=0D=0A= are hereby notified that any disclosure, copying, distribution, or=0D=0Ause= of the information contained herein (including any reliance=0D=0Athereon) = is STRICTLY PROHIBITED=2E Although this transmission and any=0D=0Aattachmen= ts are believed to be free of any virus or other defect=0D=0Athat might aff= ect any computer system into which it is received and=0D=0Aopened, it is th= e responsibility of the recipient to ensure that it=0D=0Ais virus free and = no responsibility is accepted by JPMorgan Chase &=0D=0ACo=2E, its subsidiar= ies and affiliates, as applicable, for any loss=0D=0Aor damage arising in a= ny way from its use=2E If you received this=0D=0Atransmission in error, ple= ase immediately contact the sender and=0D=0Adestroy the material in its ent= irety, whether in electronic or hard=0D=0Acopy format=2E Thank you=2E=0D=0A= =0D=0APlease refer to http://www=2Ejpmorgan=2Ecom/pages/disclosures for=0D= =0Adisclosures relating to European legal entities=2E