why does a cancel error stop the script?

I want to use this script to load files, but I also want the script to continue when the user cancels the load process by clicking cancel.
Right now the script catches the cancel error and displays “user cancelled” but the script stops there, and the script stops.
If a file is selected then the display dialog is run and the rest of the script continues.

How can I get a user cancel to let the script continue?

Much thanks for any help.
Mark


try
	set lfile to (choose file) as text
on error error_message number error_number
	if the error_number is -128 then
		beep
		display dialog error_message buttons {"Cancel"} default button 1
	end if
end try

display dialog "this should happen after error but doesn't"
display dialog "the script only continues if a file is selected"

--and there's more script here I want to continue

Because choosing “Cancel” in a file dialog window doesn’t return anything to the script you could act on. I don’t know why it cancels the script too, but it must be interpreted as an error at a higher level than your script.

Pressing “Cancel” will usually[1] generate error number -128. Unless you use a try block to do your own error handling, no error message is displayed. This gives you the benefit of not having to error handle everything the user could cancel out of.

[1] One exception to this is choose list, which will return false (boolean) if Cancel is pressed.

Thanks, Jacques - your script will do the trick nicely.

Mark