Re: Resume after exception



On Tue, 14 Jun 2005 10:09:30 +0100,
"Richard Lewis" <richardlewis@xxxxxxxxxxxxxx> wrote:

> Hi there,
> Is it possible to have an 'except' case which passes control back to the
> point after the exception occurred?

Not that I can think of.

[ example of "interrupting" a file-reading function in order to ask the
user if they really want to read a locked file ]

I would rewrite that this way (untested, and without error checking):

def open_file(file_name, read_if_locked=False):
f = file(file_name)
[read first line]
if first_line == "FILE LOCKED" and read_if_locked == FALSE:
return False
[read the rest]
return True

def open_command():
if open_file("foo.bar") == False:
[ask the user what to do]
if ans == tkMessageBox.YES:
open_file("foo.bar", True )

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
.



Relevant Pages

  • parsing columns
    ... I have no control over that... ... Regards, ... Offer Kaye ... Prev by Date: ...
    (perl.beginners)
  • Re: Heard from Firechief/ Duckie
    ... give him my regards ... | He said this puter only boots and he has no control on it. ... Prev by Date: ...
    (alt.support.arthritis)
  • Re: Setting slider value
    ... > It doesn't set the slider to 0 at all. ... Is there any code in the event handlers for that control? ... Prev by Date: ...
    (microsoft.public.vb.controls)
  • Re: Student abducted, raped by five men
    ... time for parents to take control over things ... Regards, ... Tetuang ... Prev by Date: ...
    (soc.culture.malaysia)
  • Asynchornous Method Invocation
    ... when i try to do this, the control is shown in black. ... Regards, ... Reshma ... Prev by Date: ...
    (microsoft.public.dotnet.framework.windowsforms.controls)