on error tell me to run

This works, but is it a good idea?

try
	set myMsg to "Please enter a positive integer:"
	set steps to text returned of (display dialog myMsg default answer "" buttons {"OK"} default button "OK")
	set steps to steps as integer
	if steps ≤ 0 then error
	return steps
on error
	tell me to run
end try

I’m thinking an error would create a 2nd instance of the script. Will the 1st one just sit there, doing nothing? Will it quietly die, or wait until the 2nd one finishes? If so, are they running independently? No ‘leaking’, of whatever can leak, from the 2nd into the 1st? Or am I worrying too much?

The actual script uses libraries loaded into a script server, and is run from DEVONthink’s Script Menu.
It also puts up dialogs through Pashua. It works, so far.

It depends, if it was code for NASA it was a bad idea. That is because the current machine I’m sitting behind has a stack size of 475 (seen up to 744 on some machines). That means when I make 476 mistakes I’ll get an stack overflow error. Recursive routines are considered bad when you want to write safe code. I agree with that statement if the code is capable to do infinite number of recursive calls. When you take a look at the recursive merge sort you already reach the maximum items in a list before you reach the maximum stack call.

So the question that remains is: How bad is it when an user makes 475 times a mistake resulting the code won’t run properly? The perfect solution would stop the program when an certain level of recursive calls are reached on the stack, let’s say 10 for example. If you want it to be infinite, use a loop instead.

So the script would run just fine until a stack overflow occurs?

Correct.

Keep in mind that each script object has it’s own stack. Putting this is an script object would make it a bit better.

getNumberFromUser()

on getNumberFromUser()
	script x
		try
			set myMsg to "Please enter a positive integer:"
			set steps to text returned of (display dialog myMsg default answer "" buttons {"OK"} default button "OK")
			set steps to steps as integer
			if steps ≤ 0 then error
			return steps
		on error
			tell me to run
		end try
	end script
	run x
end getNumberFromUser

The difference between the script above and yours seems small but in the script above the recursive calls are added to the stack of script x and not to the stack of the root script object. There is no performance difference but in this case the script x object can be freed after the routine is finished and the stack of the root script object contains less “garbage” and stays clean.