Why does return myFunction() work better?

I have never seen any documentation (maybe I have not looked hard enough) why you should return a function instead of just calling it.

my myFunction()


return myFunction()

From my experience it is easier to trouble shoot and cathch errors if you return a function rather just call it. StefanK I know you know this one can you help a brother out?

Can you provide a functional example where returning the function helps troubleshoot or catch an error?


return (the keyword, not the constant) is used to exit a handler immediately.
Without an argument return passes no value.
With an argument return passes the result of the argument.

Nothing more, nothing less

See also: return

I didn’t specify how I am using this but qFiler a xcode app I have used for a long time is a hot folder manager that uses applescript for plug-ins. I know part of this is because the way qFiler is made to exit the main routine on error or a return of false but the same routine I have used for years to send emails does not work unless I return a function instead of just running the function. Even if I make sure to pass all vars back to the main routine it seemed to never fire off email handlers. Once I return the function everything worked like a charm.

I know there is no difference in the function wether it is called my my myFunction or return myFunction but to me I have had much less troubles catching errors. Like StefanK said “return (the keyword, not the constant) is used to exit a handler immediately.” this allows me to pass alot of information back to the main script without having to on error return all the information.