property crlf : (ASCII character 13) & (ASCII character 10) property http_10_header : "HTTP/1.0 200 OK" & crlf & "Server: MacHTTP" & crlf & Ā "MIME-Version: 1.0" & crlf & "Content-type: text/html" & crlf & crlf property idletime : 300 property datestamp : 0 set datestamp to current date on «event WWW½sdoc» path_args ¬ given «class kfor»:http_search_args, ¬ «class post»:post_args, «class meth»:method, ¬ «class addr»:client_address, «class user»:username, ¬ «class pass»:password, «class frmu»:from_user, ¬ «class svnm»:server_name, «class svpt»:server_port, ¬ «class scnm»:script_name, «class ctyp»:content_type set datestamp to current date try set return_page to http_10_header ¬ & "<HTML><HEAD><TITLE>Unprocessed Results</TITLE></HEAD>" ¬ & "<BODY><H1>Unprocessed Results</H1>" & return ¬ & "<H4>http_search_args</H4>" & return & http_search_args set return_page to return_page & return ¬ & "<H4>post_args</H4>" & return & post_args & return ¬ & "<H4>method</H4>" & return & method & return ¬ & "<H4>client_address</H4>" & return & client_address & return set return_page to return_page & return ¬ & "<H4>from_user</H4>" & return & from_user & return ¬ & "<H4>server_name</H4>" & return & server_name & return ¬ & "<H4>server_port</H4>" & return & server_port & return set return_page to return_page & return ¬ & "<H4>script_name</H4>" & return & script_name & return ¬ & "<H4>content_type</H4>" & return & content_type & return ¬ & "<H4>username</H4>" & return & username & return ¬ & "<H4>password</H4>" & return set return_page to return_page ¬ & "<I>Results generated at: " & (current date) ¬ & "</I>" & "</BODY></HTML>" return return_page on error errMsg number errNum from suspect set return_page to http_10_header ¬ & "<HTML><HEAD><TITLE>Error Page</TITLE></HEAD>" ¬ & "<BODY><H1>Error Encountered!</H1>" & return ¬ & "An error was encountered while trying to run this script." & return set return_page to return_page ¬ & "<H3>Error Message</H3>" & return & errMsg & return ¬ & "<H3>Error Number</H3>" & return & errNum & return ¬ & "<H3>Suspected Target</H3>" & return & suspect & return ¬ & "</BODY></HTML>" return return_page end try end «event WWW½sdoc» on idle if (current date) > (datestamp + idletime) then quit end if return 5 end idle on quit continue quit end quit
tryThis line, added at the start of the AppleEvent handler, tells AppleScript that you have provided an error handler (see below) in the event of an error. The usual "try" statement looks like the following:
try [some statements to try to do without error] on error [statements to do if an error occurs] end tryThe "on error" handler is part of the try statement. Therefore, the "end try" line ends the whole statement, including the error handler.
on error errMsg number errNum set return_page to http_10_header ¬ & "<HTML><HEAD><TITLE>Error Page</TITLE></HEAD>" ¬ & "<BODY><H1>Error Encountered!</H1>" & return ¬ & "An error was encountered while trying to run this script." & return set return_page to return_page ¬ & "<H3>Error Message</H3>" & return & errMsg & return ¬ & "<H3>Error Number</H3>" & return & errNum & return ¬ & "</BODY></HTML>" return return_page end tryThis is the error handling code. If an error occurs after the try statement, this handler is run. It is passed a number of variables. Here we are using just the two standard parameters:
As you can see in the code above, nothing is really new in this handler. All it does is create an HTML page to return that contains the error information. By passing back an HTML page, the user gets two benefits: