For the demonstrated purpose setjmp()-longjmp() should be better, because it saves/restores registers and gives a return value.
non-local-gotos are implemented using setjmp/longjmp.
I have never tried nonlocal gotos. Theoretically these could be used to jump into a loop or into a procedure, which is a horrible idea for me.
With setjmp/longjmp you must initialize jmp_buf, which stores the location and registers and you can return and you get a return value. You can only jump
back to a location, where you have been before you cannot jump to arbitrary locations.
This is very different.
Experimental code example: Variable "pos" is the jmp_buf, which stores registers and execution point.
while True do
try
while (true) do
begin
if setjmp(pos) > 0 then //"pos" stores registers and execution point here into jmp_buf record.
writeln('Error! Please input integer number!');
readln(N);
...... //code which may raise exception can modify "pos" so
......//the exception always returns to the point where it was raised.
end;
except
on E: EInOutError do
begin
longjmp(pos, 1);
// Writeln(E.ClassName, ': ', E.Message);
end;
end;
Simplifies error handling, if you have multiple "readln" lines which can raise exceptions in the code.
Can you do this with nonlocal goto?