Re: Return from Handler... What am I Missing Here?
Re: Return from Handler... What am I Missing Here?
- Subject: Re: Return from Handler... What am I Missing Here?
- From: Shane Stanley <email@hidden>
- Date: Sun, 18 Oct 2015 11:42:24 +1100
On 18 Oct 2015, at 7:48 AM, S. J. Cunningham <email@hidden> wrote:
>
> But why does it return "x" instead of {errNum:-1, errMsg:"x"}
Because not all statements return a result. When you call your handler, the line:
set yyy to "x"
returns a result ("x"). But the next line:
return {errNum:-1, errMsg:yyy}
returns a value to the caller, but it does not return a result. So at the point the handler returns, result is still "x".
In Case 1 you called the handler like this:
handlerName()
That statement returns a result, which is the value returned by the handler ({errNum:-1, errMsg:yyy}).
In Case 2 you called it like this:
if errNum of handlerName() ≠ 0 then
That's a control statement that doesn't return a result, which means the result variable remains as it was before that statement: "x".
As others have said, steer clear of the result variable. It has the potential to cause too much grief.
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden