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!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:module': 0.04; 'exception,': 0.07; 'received:209.85.213.46': 0.07; 'received :mail-yw0-f46.google.com': 0.07; 'though.': 0.07; 'python': 0.07; ':-)': 0.07; 'exception.': 0.09; 'pm,': 0.11; '>>>': 0.12; 'exception': 0.12; 'wrote:': 0.14; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '[gcc': 0.16; 'linux2': 0.16; 'mrab': 0.16; 'traceback': 0.16; '(most': 0.16; 'classes,': 0.19; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'header:In- Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'thu,': 0.22; 'last):': 0.23; 'received:209.85.213': 0.23; 'typically': 0.24; 'skip:_ 20': 0.24; 'define': 0.26; 'pass': 0.27; 'raise': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.31; 'fact': 0.31; "isn't": 0.34; 'regular': 0.34; 'file': 0.35; 'header:User-Agent:1': 0.35; 'put': 0.35; '"",': 0.35; 'received:128': 0.36; 'charset:us- ascii': 0.36; 'else': 0.37; 'received:209.85': 0.37; 'andrew': 0.38; 'received:google.com': 0.38; 'anything': 0.38; 'hello!': 0.39; 'received:209': 0.39; 'how': 0.39; 'would': 0.40; 'header:Received:5': 0.40; 'skip:h 20': 0.60; '2011': 0.62; 'subject:handle': 0.84 Date: Thu, 12 May 2011 15:26:27 -0500 From: Tycho Andersen To: Andrew Berg Subject: Re: Proper way to handle errors in a module References: <4DCC318E.7020809@gmail.com> <4DCC3421.9070007@mrabarnett.plus.com> <4DCC3F37.3010904@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4DCC3F37.3010904@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: python-list@python.org 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: 24 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305231999 news.xs4all.nl 81483 [::ffff:82.94.164.166]:55234 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5258 On Thu, May 12, 2011 at 03:12:39PM -0500, Andrew Berg wrote: > On 2011.05.12 02:25 PM, MRAB wrote: > > You can raise an exception wherever you like! :-) > If I raise an exception that isn't a built-in exception, I get something > like "NameError: name 'HelloError' is not defined". I don't know how to > define the exception. You'll have to define it, as you would anything else (exceptions are just regular "things"; in fact you can raise anything that's a class or instance). I typically don't put a whole lot in my exception classes, though. point:~/working$ python Python 2.6.2 (r262:71600, Jun 8 2009, 11:11:42) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class HelloError(Exception): pass ... >>> raise HelloError("hello!") Traceback (most recent call last): File "", line 1, in __main__.HelloError: hello! \t