Cancel script from running when button "No" is selected

:slight_smile: Please can someone advise why this is not working. I need the script to stop running when the user select “no”. (I’m only posting the section I’m having trouble)

try
			set thisButton to button returned of (display dialog "Do you had enough time to choose the PDF style setting Resort Directory for Press" with icon caution buttons {"Yes", "No"} default button 1)
			if thisButton is "Yes" then
				close document 1 saving no
			end if
			if thisButton is "No" then
				error number -128 --I want the script to stop
				display dialog "You have to START the script again from Sript Editor" with icon caution buttons {"Cancel"} default button 1
			end if
		end try

Hi,

the problem is probably the try block, which ignores any error silently.
A short version is


display dialog "Do you had enough time to choose the PDF style setting Resort Directory for Press" with icon caution buttons {"Yes", "No"} cancel button "No" default button 1
close document 1 saving no

the “No” button will be assigned to the behavior of the Cancel button.
If the user presses “No” the script stops

Thank you very much. It worked:lol::lol::lol: