Quicky: Trying again on error

I have a SOAP handler that occasionally times out in a try block and returns an error to the caller. Simply trying again often works. In the caller, I test for the error and display a dialog if it occurs.

I’d like to have two buttons: “Try Again” and “Quit”, but don’t know how to restart the calling script from within itself. In ancient times, I would have used “goto” programming (head hanging, one foot over the other).

How is that done in an AppleScript? I don’t have to go all the way back to the beginning, just repeat the SOAP call.

Is this what you talking? :lol:


if "true" is "true" then Mysoaphandler() --Used the handler in a statement for example


on Mysoaphandler()
	--commands of the handler here
	display dialog "Soap handler is running"--Example command of a handler, to be removed
	try
		display dialog theError --Kicks out an error since theError is undefined
	on error
		set UI to display dialog "The handler got an error. Re-execute the handler?" buttons {"Cancel", "Try again"} default button "Try again"
		set ButtonName to button returned of UI
		if ButtonName is "Try Again" then
			Mysoaphandler() --Recalls the handler, as in "Goto"
		else
			if ButtonName is "Cancel" then quit --Quits on cancel
		end if
	end try
end Mysoaphandler

SC

Excellent. It wasn’t occurring to me to simply recall the handler itself. A little rearranging of my script makes that possible because nothing else changes. The only problem I see is handling a second timeout - I’ll think on it.

What I have now is:

-- all the setup stuff...

property agio : 0.02 -- fee added by bank to Xchg rate, half the "spread"
-- Exchange Rates
set XchR to Xchg("United States", "Canada")
if XchR = "oops" then
	display dialog "Sorry, SOAP server timed out" buttons {"Try Again", "Quit"} default button 1
	set BTN to button returned of result
	if BTN is "Try Again" then set XchR to Xchg()
	if XchR = "oops" then quit
	if BTN is "Quit" then quit
end if

-- put it together
set us_cdn to round_truncate((item 1 of XchR) + agio, 3) as number
set cdn_us to round_truncate((item 2 of XchR) + agio, 3) as number

etc.