This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Built-in Functions / New in Version 3.0 / Programming  /

  • Throw[ value ] stops evaluation and returns value as the value of the nearest enclosing Catch.
  • Throw[ value , tag ] is caught only by Catch[ expr , form ] where form is a pattern that matches tag.
  • You can use Throw and Catch to exit functions such as Nest, Fold, FixedPoint and Scan.
  • tag can be any expression.
  • tag in Throw[ value , tag ] is re-evaluated every time it is compared to form in Catch[ expr , form ].
  • An error is generated and an unevaluated Throw is returned if there is no appropriate enclosing Catch to catch the Throw.
  • See the Mathematica book: Section 2.5.9.
  • See also: Return, Goto, Interrupt, Abort.

    Further Examples

    This definition makes g throw overflow if its argument is greater than 10.