Re: Error trap if item cannot be made into an integer?
Re: Error trap if item cannot be made into an integer?
- Subject: Re: Error trap if item cannot be made into an integer?
- From: email@hidden
- Date: Tue, 19 Nov 2002 01:49:10 EST
In a message dated 11/19/02 Kenton Muschenheim writes:
>
I'm looping through items in a list and I want to skip the item if the item
>
name can't be made into an integer. What's the syntax to trap the "Can't
>
make into an integer" error?
To find out the message and number of a particlar error, run this:
try
"two" as integer
on error errMsg number errNum
error errMsg & space & errNum
end try
which tells you that -1700 is the error generated when a string can't be
coerced to an integer. Your loop, therefore, might look like this:
set thelist to {"1", "two", "3"}
set integerList to {}
repeat with oneItem in thelist
try
copy oneItem as integer to end of integerList
on error number -1700
end try
end repeat
return integerList
You'll also notice that this script works just as well with "number -1700"
commented out. That means you're just skipping over any item that generates
any kind of error when you try to coerce it to an integer. I can't imagine
what other errors those might be.
I'll hereby confess that when I've had to deal with this situation, I'm
usually too lazy to bother with specifying an error number. If that's a
dangerous practice, I hope someone will correct me.
Robert Kyle
Star Tribune
Minneapolis
(where, btw, the IT experts say we can be just as productive and happy using
PCs and VB)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.