• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Throwing Errors in Functions?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Throwing Errors in Functions?


  • Subject: Throwing Errors in Functions?
  • From: Alex Hall <email@hidden>
  • Date: Tue, 10 Mar 2015 23:56:11 -0400

Hello list,
I've seen plenty about catching errors in try/on error blocks, and I've used them many times. I'm calling my own functions, though, and I'd like to use errors instead of a return code or checking the class of the returned item to see if my functions worked. That is:

on doMyFunction(x)
if x<10 then
throw msg "x cannot be less than 10." number -1
end if
return "x="&(x as text)
end doMyFunction

try
set y to doMyFunction(5)
display dialog "It worked, " & (y as text)
on error msg number eNumber
display dialog "error " & eNumber & ": " & msg
end try

Of course, the bit that I'm not sure about is my made-up "throw" statement. Does AS have a native way of doing this, or is it down to return codes/values? Thanks!

--
Have a great day,
Alex Hall
email@hidden

 _______________________________________________
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

  • Follow-Ups:
    • Re: Throwing Errors in Functions?
      • From: Luther Fuller <email@hidden>
    • Re: Throwing Errors in Functions?
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Don't understand delay action
  • Next by Date: Re: Throwing Errors in Functions?
  • Previous by thread: Re: Don't understand delay action
  • Next by thread: Re: Throwing Errors in Functions?
  • Index(es):
    • Date
    • Thread