• 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
Re: Throwing Errors in Functions?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Throwing Errors in Functions?


  • Subject: Re: Throwing Errors in Functions?
  • From: Luther Fuller <email@hidden>
  • Date: Wed, 11 Mar 2015 08:24:36 -0500

I use the following 'run' handler in all of my application scripts.

on run
try
my main()
on error errText number errNr
if errNr = -128 then
return
else if errNr = -2700 then
my showInstruction(errText)
else
my showError(errText, errNr, false)
end if
end try
end run -------------------------------------------------------

If you arrive at a point in your script where you want to simply quit, you use the instruction

error number -128

If you encounter a condition that does not allow continuation of the script, use this instruction
which uses the showInstruction handler

error "Explain to the user why continuation was not possible." -- returns error number -2700

All other errors are unknown to your script and use the showError handler.
The showError handler simply shows the error number and text.
Here's my showInstruction handler ...

on showInstruction(instText)
set dTitle to "Instruction"
activate me
tell me to display alert dTitle message instText buttons {"Help", "OK"} default button "OK"
if (button returned of the result) = "OK" then return
tell application "Finder" to open file (((path to me) as text) & pathToHelp) using application file id "com.apple.helpviewer"
end showInstruction --------------------------------------------------------


 _______________________________________________
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: Alex Hall <email@hidden>
References: 
 >Throwing Errors in Functions? (From: Alex Hall <email@hidden>)

  • Prev by Date: Re: OffTopic : error reported in Console
  • Next by Date: Re: Yosemite and activate failures
  • Previous by thread: Re: Throwing Errors in Functions?
  • Next by thread: Re: Throwing Errors in Functions?
  • Index(es):
    • Date
    • Thread