functionprogramming-languages

What is a non-local return?


What is non local return? In what scenarios it is useful? Please give an example to explain.


Solution

  • It means exiting a function and ending up someplace else beside where the function was called. It's primarily used to refer to exceptions (i.e., try, throw, and catch in Java and C++), but it can also mean mechanisms like setjmp/longjmp in C.