Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.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.044 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'failing': 0.07; 'finally:': 0.07; 'modes': 0.09; 'try:': 0.09; 'cc:addr:python- list': 0.11; '(within': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'reraise': 0.16; 'unexpected': 0.16; '(you': 0.16; 'prevent': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'trying': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'skip:e 30': 0.24; 'cc:2**0': 0.24; '15,': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'database,': 0.30; 'message- id:@mail.gmail.com': 0.30; 'getting': 0.31; 'catching': 0.31; 'there.': 0.32; 'supposed': 0.32; "i'd": 0.34; 'could': 0.34; 'advice': 0.35; 'agree': 0.35; 'anywhere': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'raising': 0.36; 'reality': 0.36; 'should': 0.36; 'loss': 0.38; 'nov': 0.38; 'pm,': 0.38; 'catch': 0.60; 'failures': 0.60; 'most': 0.60; 'royal': 0.61; 'within': 0.65; 'life': 0.66; 'importantly,': 0.68; 'restore': 0.78; 'coherent': 0.84; 'execution.': 0.84; 'pardon': 0.84; 'recover': 0.91; 'smoke': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=scXZmiYQ8VnYqc2/VFkHTesivj2IgAaMP7z774LKZ90=; b=gf0ARpX5yDx5NyCFrzeoiYp+/IsokjiTiKTCtv297Hyqf8Vz6aj4f9Fxf9T7atb9NY 1NILY49Rj0wB+283J/j5XVdeuZFZMOzO5CWLDcRNplrm12OUEoMBmi12qem8GH4U1eXh qj75JPdGZKAyyNDMFNFynf29ejC09Ck5qsED7t9w3obRld+mSE6uuul4ibVo6wWqy0sK tqgH4R9xTeBcETI3de3xRxB2sRdK2IPA29bjat6ZNbAb+etA8GaxzFzOq3wq1WZluQGj rIq2V/U+KQdFFNYUElKoGwETZurdE3x+PEQ6V0HNafMBLhruWtvLfPuSaysSAxbiIDW0 h7NA== MIME-Version: 1.0 X-Received: by 10.107.132.37 with SMTP id g37mr14085691iod.21.1416016124354; Fri, 14 Nov 2014 17:48:44 -0800 (PST) In-Reply-To: <87a93tl07u.fsf@elektro.pacujo.net> References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <87a93wqeq3.fsf@elektro.pacujo.net> <87y4rgozgd.fsf@elektro.pacujo.net> <0cdc67f4-d9d5-4a73-91fe-7558161246af@googlegroups.com> <28e159ff-3d64-4793-9082-05cf1553c7c2@googlegroups.com> <87h9y4owgc.fsf@elektro.pacujo.net> <54669308$0$13002$c3e8da3$5496439d@news.astraweb.com> <87h9y1l3tt.fsf@elektro.pacujo.net> <87a93tl07u.fsf@elektro.pacujo.net> Date: Sat, 15 Nov 2014 12:48:44 +1100 Subject: Re: I love assert From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416016126 news.xs4all.nl 2943 [2001:888:2000:d::a6]:39068 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80799 On Sat, Nov 15, 2014 at 12:30 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Nov 15, 2014 at 11:12 AM, Marko Rauhamaa wrote: >>> Most importantly, assertion failures are not supposed to be recovered >>> from (within the program). Assertion failures can result in the loss >>> of life and limb. They can result in database corruption. They can >>> result in monetary losses. They can result in smoke coming out of the >>> monitor. >> >> Or, in theory, AssertionError just prevented any of the above from >> happening. > > I'd advice against catching AssertionError and trying to recover from it > within the program. You could catch it, log it and reraise it, but since > the failure modes could be completely unexpected (really, by > definition), I would move fault-tolerance outside the failing process > and try to restore a coherent reality from there. I agree - never catch it. But you should be able to prevent database corruption: conn = establish_database_connection() try: do_stuff() finally: conn.rollback() The raising of AssertionError anywhere inside do_stuff() will prevent craziness from getting to the database, because it aborts the execution. (You know, the way a royal pardon does.) ChrisA