Re: Repeat-Dialog-Error
Re: Repeat-Dialog-Error
- Subject: Re: Repeat-Dialog-Error
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 28 Feb 2001 19:28:16 -0800
On 2/28/01 6:45 PM, "Brad Giesbrecht" <email@hidden> wrote:
>
Hello,
>
>
<snip>
>
try
>
repeat while (not done)
>
set x to the button returned of --optionreturn
>
(display dialog "" buttons {"Cancel", "Look", "Continue"} as text
>
set done to true
>
if x is "Look" then
>
process_windows()
>
set done to false
>
end if
>
end repeat
>
on error
>
display dialog "Cancel failed."
>
end try
>
<snip>
>
>
Why when I click the cancel button, do I get the
>
"Cancel failed" dialog.
>
Because "Cancel" is actually an error, error number -128 to be precise. So
if if you want a dialog to display an error, but NOT when a user cancels
somewhere, you can use that to advantage:
try
--some stuff
on error errMsg number errNum
if errNum /= -128 then
display dialog errMsg with icon 0
end if
end try
However, it might also be a good idea not to put a try block around an
entire script, which won't really help you much if it errors. If you put
several try blocks around different parts of the script which might error,
with an identifying marker, like
if x is "Look" then
try
process_windows()
set done to false
on error errMsg number errNum
if errNum /= -128 then
display dialog "process_windows handler:" & return & errMsg with
icon 0
end if
end try
end if
Or better yet, put the try blocks within the handler.
/= means "does not equal", by the way, and will compile.
--
Paul Berkowitz