What techniques work to handle errors in AppleScript so I can place a dialog? I'm new to programming and AppleScript and I have lots of problems with error handling.

Could anybody share their error handling for file operations like move/trash files? Here is my code so far:

try
tell application "Finder" to open file file_path
on error e number n
if e contains "Can’t get file" then say "mount external drive" --file not found, maybe this hard drive is not mounted
if e is x then something
end try
In general it's advisable to handle errors based on the error number and not on the text (which is language dependent and much more difficult to handle than some numbers). In addition start with just displaying the error number/messages to understand what really went wrong:

try
tell application "Finder" to open file file_path

on error error_message number error_number
display dialog "Error: " &amp; the error_number &amp; ": " &amp; the error_message buttons {"OK"} default button 1
end try


Once you know the potential error codes you want to handle specifically you can extend this to

try
tell application "Finder" to open file file_path

on error error_message number error_number
    if error_number = -1728 then
        display dialog "Can't read file."
    else
        display dialog "Error: " &amp; the error_number &amp; ": " &amp; the error_message buttons {"OK"} default button 1
    end if
end try