Re: Quit handler not working
Re: Quit handler not working
- Subject: Re: Quit handler not working
- From: Nigel Garvey <email@hidden>
- Date: Sat, 5 Jun 2004 22:14:04 +0100
Ken Tozier wrote on Fri, 4 Jun 2004 21:19:15 -0400:
>
I defined a quit handler in a "run and stay open" applet like so
>
>
on quit
>
Deinitialize()
>
continue quit
>
end
>
>
In my "initialize" method I'm validating the return from each command
>
inside a try block like so
>
>
try
>
set prop1 to (* prop 1 initializer *)
>
on error
>
quit
>
end
>
>
try
>
set prop2 to (* prop 2 initializer *)
>
on error
>
quit
>
end
>
The problem is, if the first try encounters an error, the quit handler
>
doesn't actually quit the script. It goes merrily along as if nothing
>
happened and performs the second, third, fourth try blocks. Is there a
>
way to absolutely, no exceptions quit an applet in a situation like
>
this?
The 'quit' command is for the script's application component. The
application does take note of it, but only actually quits when it's
finished running the script. You need something to stop any more of the
script from being executed. That's the "User canceled" error:
try
set prop1 to (* prop 1 initializer *)
on error
quit
error number -128
end
Note that the 'quit' command has to come before the error command,
because nothing after the error gets executed. Another approach - or one
that might be combined with it - is to put all your initialisation into
the 'same' try block:
try
set prop1 to (* prop 1 initializer *)
set prop2 to (* prop 2 initializer *)
on error
quit
error number -128
end
If "prop 1 initializer" errors, the action leaps straight to the 'on
error' section and "prop2 initializer" is thus bypassed.
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.