Throw
Throw(value)
stops evaluation and returns
value
as the value of the nearest enclosingCatch
.Catch(value, tag)
is caught only byCatch(expr, form)
, wheretag
matchesform
.
Examples
Using Throw
can affect the structure of what is returned by a function:
>> NestList(#^2 + 1 &, 1, 7){1,2,5,26,677,458330,210066388901,44127887745906175987802}
>> Catch(NestList(If(# > 1000, Throw(#), #^2 + 1) &, 1, 7))458330
A Throw
without an enclosing Catch
prints the message: Uncaught Throw(1) returned to top level.
>> Throw[1]Hold(Throw(1))
Implementation status
- ✅ - full supported