# catch AppleScript error



## vettezuki (Oct 21, 2005)

My AppleScript is calling a console app with "do shell script."  I would like to get the integer return from this console app.  According to Apple:



> A: All shell commands return an integer status when they finish: zero means success; anything else means failure. If the script exits with a non-zero status, do shell script throws an AppleScript error with the status as the error number. . . .



Great, how do I catch an AppleScript error?  Digging, through docs, haven't found answer yet.  Please to help.


----------



## Mikuro (Oct 21, 2005)

I think you need to use a TRY statement. Something like this:
	
	



```
try
	set x to "a" * 2 --something to cause an error
on error error_string number error_number
	return {error_string} & {error_number}
end try
```
For more info on TRY statements, see the AppleScript Language Guide, which is available in HTML and PDF forms at http://www.apple.com/macosx/features/applescript/resources.html


----------



## vettezuki (Oct 21, 2005)

Yep that's the conclusion I came to also, here's what I ended up with:


```
try
		do shell script exec
	on error number errNum
		set dumb to 1
		if (errNum is 5) then
			(display dialog "Input file does not appear to be of the correct format.  I f*ng quit.")
		else
			-- If any other error do nothing.
		end if
	end try
	
	
	if (dumb is 0) then
		display dialog "File processed successfully."
	end if
```


Because I can't directly get integer return of the called appliation, I have to use a dumb variable to handle the nothing bad happened case, or at least so it seems to me now.


----------

