Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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.036 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'cpython': 0.05; 'exception.': 0.07; 'raised': 0.07; 'try:': 0.07; 'file,': 0.15; 'received:209.85.161.174': 0.16; 'wrote:': 0.17; 'char': 0.17; 'else,': 0.17; 'windows': 0.19; 'work.': 0.23; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; "doesn't": 0.28; 'file': 0.32; 'traceback': 0.33; 'handle': 0.33; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'open': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'really': 0.36; 'except': 0.36; 'message-id:@gmail.com': 0.36; 'should': 0.36; 'bad': 0.37; 'detail': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'help': 0.40; 'skip:u 10': 0.60; 'matter': 0.61; 'helps': 0.63; 'skip:6 10': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.63; '"it': 0.91 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=TNspAFxvjf2S9yx4EvXrzfzSdMtphoLAaFwZpVKII9Y=; b=cPfBhVu3n8QQVIfMStAcuyx9F49phRKVAmkidmPFpbYxelDjTISgfVpZxaOxwjeKXB tPOqNXlR0ruBOFIB75w5hy78G06KaTrl3c9JnpfZD+Weu5nIwBEoPvM3EnbaWtOPbxCI 0zhWMPh/QX22+wIW3Jauss8UPxaODf5gvI673us0Pp9u81ICW2npinBREcSurmA9Jidf 31bbKETTZ653wSz/so14hzhv6zeQm2ML9LeCy7Za0JSPqcaY5W+yZsAyjoP2R6JUgqGi nrdxoEQFyzZXfsGVTfj9BjwD9gl+dU2AX66iEMJx7UMm6esLncsVhczJc0rfUxaKGwMP /SZQ== Date: Wed, 25 Jul 2012 06:34:53 -0500 From: Andrew Berg User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: "comp.lang.python" Subject: Re: catch UnicodeDecodeError References: <04f7ff8d-9881-4a04-ab2e-b5573b5f3cd1@googlegroups.com> In-Reply-To: <04f7ff8d-9881-4a04-ab2e-b5573b5f3cd1@googlegroups.com> X-Enigmail-Version: 1.4.3 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343216109 news.xs4all.nl 6951 [2001:888:2000:d::a6]:36122 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26037 On 7/25/2012 6:05 AM, jaroslav.dobrek@gmail.com wrote: > What I really want to do is use something like > > try: > # open file, read line, or do something else, I don't care > except UnicodeDecodeError: > sys.exit("Found a bad char in file " + file + " line " + str(line_number) > > Yet, no matter where I put this try-except, it doesn't work. > > How should I use try-except with UnicodeDecodeError? The same way you handle any other exception. The traceback will tell you the exact line that raised the exception. It helps us help you if you include the full traceback and give more detail than "it doesn't work". -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803