Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed5.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.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'displayed': 0.03; 'subject:module': 0.04; 'one?': 0.05; 'array.': 0.09; 'exceptions': 0.09; 'scripts': 0.10; 'exception': 0.12; 'answer,': 0.16; 'received:mail.comcast.net': 0.16; 'wednesday,': 0.16; 'shell': 0.19; 'wondering': 0.19; 'to:2**1': 0.20; 'programming': 0.20; '(and': 0.22; "didn't": 0.25; 'expect': 0.26; '-----': 0.26; "i'm": 0.26; 'url:mailman': 0.27; "doesn't": 0.28; 'developers': 0.28; 'beyond': 0.28; 'raise': 0.29; 'error': 0.29; '(the': 0.30; 'to:addr:python-list': 0.32; 'screen': 0.32; 'url:listinfo': 0.33; 'example,': 0.33; 'subject:': 0.33; 'bit': 0.33; 'array': 0.33; 'module': 0.33; 'sometimes': 0.33; 'certain': 0.34; 'module.': 0.35; 'trigger': 0.35; 'considered': 0.36; 'some': 0.37; 'url:python': 0.37; 'andrew': 0.38; 'but': 0.38; 'url:org': 0.38; 'sent:': 0.39; 'errors': 0.39; 'end': 0.39; 'set': 0.39; 'to:addr:python.org': 0.39; 'comes': 0.39; 'from:': 0.39; 'finished': 0.40; 'would': 0.40; 'might': 0.40; 'best': 0.60; 'happen': 0.61; 'reached': 0.61; '2011': 0.62; 'direction.': 0.65; 'show': 0.67; '11,': 0.77; 'message?': 0.84; 'subject:handle': 0.84; 'window,': 0.84 From: "Patty" To: "Andrew Berg" , References: <4DCAC78E.1000901@gmail.com> Subject: Re: Proper way to handle errors in a module Date: Wed, 11 May 2011 10:57:49 -0700 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6090 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: 40 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305136755 news.xs4all.nl 81476 [::ffff:82.94.164.166]:60391 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5138 ----- Original Message ----- From: "Andrew Berg" To: Sent: Wednesday, May 11, 2011 10:29 AM Subject: Proper way to handle errors in a module > I'm a bit new to programming outside of shell scripts (and I'm no expert > there), so I was wondering what is considered the best way to handle > errors when writing a module. Do I just let exceptions go and raise > custom exceptions for errors that don't trigger a standard one? Have the > function/method return nothing or a default value and show an error > message? I'm sure there's not a clear-cut answer, but I was just > wondering what most developers would expect a module to do in certain > situations. > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi Andrew - Sometimes you want an exception come up and then use that information to take your program in some direction. For example, you might want your program to 'see' the exception that comes up when you go one beyond the end of an array. This means that something you wanted to happen within the array you set up finished successfully (the program just reached one beyond it and you didn't get an error!). The enduser doesn't need to see this displayed on the screen or in a window, you can just use an exception as-is to your advantage within the program. Regards, Patty