Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!feed.xsnews.nl!border-2.ams.xsnews.nl!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'argument': 0.05; 'cpython': 0.05; 'exception': 0.05; 'debugging': 0.07; 'attributes': 0.09; 'clause': 0.09; 'debugging.': 0.09; 'mask': 0.09; 'means,': 0.09; 'omit': 0.09; 'propagate': 0.09; 'sections': 0.13; 'give.': 0.16; 'handlers': 0.16; 'logger': 0.16; 'subject:exception': 0.16; 'unexpected': 0.16; 'user-defined': 0.16; 'wrote:': 0.17; 'windows': 0.20; 'lets': 0.22; 'subject:problem': 0.22; 'programming': 0.22; 'header:In-Reply- To:1': 0.23; 'tutorial': 0.24; 'print': 0.25; 'header:User- Agent:1': 0.26; 'normally': 0.27; 'statement': 0.27; 'error': 0.28; '"the': 0.28; "doesn't": 0.28; 'exceptions': 0.29; 'informative': 0.29; 'terminate': 0.29; 'figure': 0.29; 'function': 0.29; '(most': 0.30; 'am,': 0.30; 'especially': 0.31; '(and': 0.31; 'message.': 0.31; 'generally': 0.32; 'could': 0.33; 'module.': 0.33; 'received:google.com': 0.34; 'agree': 0.35; 'received:209.85': 0.35; 'feed': 0.35; 'to:addr:python-list': 0.35; 'except': 0.35; 'there': 0.35; 'serve': 0.36; 'really': 0.36; 'does': 0.36; 'but': 0.36; 'subject:: ': 0.37; 'received:209': 0.37; 'some': 0.38; 'explain': 0.38; 'message- id:@gmail.com': 0.38; 'method': 0.39; 'useful': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.39; 'several': 0.40; 'simply': 0.60; 'easy': 0.60; 'simple': 0.60; 'skip:6 10': 0.61; 'stand': 0.61; 'information': 0.62; 'kind': 0.62; 'more': 0.63; 'real': 0.63; 'different': 0.63; 'times': 0.64; "you'll": 0.65; 'bare': 0.84; 'absolutely': 0.85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=XsNiDIUIcA7+mNuBvJbyLoHGkdFgK6j/C4WSwgUvms0=; b=Ee/83XDLmLqS0/q3LW40fiiIpw/A5jqGQXANmXt8vmPpRfoaBGkU+wbgHXulxuFbUh NkaFxsO98sWMWV0xinrAYFPiTT2cGhxbvZ7jDZ9XEQwZxSkMo1TW99g2bBWoYXjUjBk8 Tmko3QjkcRcH1L2RAN8eAPthUVHHmJbCKr+09jH+7nt9MsOb5s/IzFDmo8kMfo3qKIPa ypAE0DDoH2lKD/feOBo+2Gcr525oo9jsUnVpryw5RYFWlftYkKMDE9cYFPGrMOwZRIQW Hjq77ijIaFpm288dXMJpgid4aOozGHesLNEWQvgpXBerpWxTDqoYRDZ3zhwnrN8EWYQu D+7g== Date: Mon, 25 Jun 2012 01:23:52 -0500 From: Andrew Berg User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: "comp.lang.python" Subject: Re: exception problem References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> <4FE7F6CC.2050704@earthlink.net> In-Reply-To: <4FE7F6CC.2050704@earthlink.net> X-Enigmail-Version: 1.4.2 Content-Type: text/plain; charset=UTF-8 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1340605453 news.xs4all.nl 6859 [2001:888:2000:d::a6]:60033 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:24416 On 6/25/2012 12:27 AM, Charles Hixson wrote: > The documentation section covering the except statement could stand to > be a *LOT* clearer. I read the sections on the except statement and > exception handlers several times and couldn't figure out was the "as" > argument of the except statement was for. I agree that the tutorial doesn't explain the use of "as" very well, but it does cover that a bare except is not normally good to use: "The last except clause may omit the exception name(s), to serve as a wildcard. Use this with extreme caution, since it is easy to mask a real programming error in this way!" > I still don't really know what > "as" means, except that if you use it, and you print out the "target", > you'll get some kind of informative message. "as" lets you refer to the exception object that was caught. I find this useful mainly for exceptions that have attributes (most built-in exceptions don't, but many user-defined exceptions do). A full traceback is much more useful for debugging than what a simple print(exc) will give. There are a few different ways to get traceback information without letting the exception simply propagate and terminate the program. You can get some simple information from sys.exc_info() (and you can feed the traceback object to a function in the traceback module), or you can log it with the logging.exception() function or the exception() method of a Logger from the same module. I recommend using logging. However, it's generally best to just let any unexpected exceptions propagate unless the program absolutely must continue, especially when debugging. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803