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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'bug': 0.02; 'subject:module': 0.04; 'value,': 0.04; 'parameter': 0.05; 'exceptions': 0.09; 'pm,': 0.11; 'exception': 0.12; 'wrote:': 0.14; 'otoh,': 0.16; 'unhandled': 0.16; 'developer': 0.16; 'wondering': 0.19; '(which': 0.21; 'header:In-Reply-To:1': 0.22; 'right,': 0.22; 'module,': 0.23; 'calling': 0.25; 'script': 0.26; "i'm": 0.26; 'function': 0.27; 'raise': 0.29; 'error': 0.29; 'message-id:@gmail.com': 0.30; 'annoying': 0.31; 'to:addr:python- list': 0.32; 'things': 0.33; 'module': 0.33; 'sometimes': 0.33; 'received:192.168.1': 0.34; 'received:192': 0.34; 'force': 0.35; 'header:User-Agent:1': 0.35; 'occurs': 0.35; 'doing': 0.36; 'none': 0.36; 'problems': 0.37; 'received:192.168': 0.37; 'some': 0.37; 'should': 0.37; 'received:209.85': 0.37; 'andrew': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'errors': 0.39; 'to:addr:python.org': 0.39; 'could': 0.39; 'where': 0.39; 'received:209': 0.39; 'how': 0.39; 'would': 0.40; 'header:Received:5': 0.40; 'necessarily': 0.40; 'learn': 0.60; 'direction.': 0.65; 'harder': 0.65; 'hand,': 0.72; 'received:209.85.210.174': 0.84; 'received:mail- iy0-f174.google.com': 0.84; 'subject:handle': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=7ANM4REBctKzUrsrBHqtdPYOey6DPlDWM+eJcOrQuY4=; b=OpZuaIrdtGxMYmWEyxlVGhOFQhKKurXkCFXTaSvOc0EanzEdpo//K0uqPb5o0A5MAv 2Alo6E5QdvYYliQ/481+2M8c8q21pJa6/gryuMSql1FGwecD0RiKIBlNz5JUnU3eUJmD kiiCt3HUNwXuVTQoruipZMj85Tn9TpbU5UkUw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; b=E0NsgIPQJt4kAVgnObFSuibQCNcPZBqbVmUwKul0T4AMldyMg0vxt/7N29lJSOgWEz Rxqjb2u7w+uIjcg9AAs47+kpbf9sNwqvS5pwuqODyhB75H+X3qvb2Fn4CEjDi9BjO+8E AIiB9Nkg/sDhiNrGo6jpQIH0vWhrZO5q0uASQ= Date: Wed, 11 May 2011 13:14:39 -0500 From: Andrew Berg User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 ThunderBrowse/3.3.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Proper way to handle errors in a module References: <4DCAC78E.1000901@gmail.com> <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> In-Reply-To: <0CCEE1DAE6B2478CB150177F57E58B7B@mycomputer> X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 19 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305137685 news.xs4all.nl 81479 [::ffff:82.94.164.166]:53983 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5147 On 2011.05.11 12:57 PM, Patty wrote: > Hi Andrew - > > Sometimes you want an exception come up and then use that information to > take your > program in some direction. Right, but I'm wondering how I should handle errors in a module, where different people will want their programs to do different things when an error occurs in a function or method from my module (which is not necessarily because of a bug in my module - the calling script could send a bad parameter or some system configuration could prevent the function from doing something). On one hand, I could let almost all exceptions go unhandled and have the calling script handle them. This would force the developer of the calling script to learn all the exceptions that my module could raise (which could be really annoying if I have custom exceptions for problems that don't otherwise raise an exception). OTOH, I could handle all the exceptions and return None or some default value, but that would make it harder for the developer to make the script react appropriately.