Navigation
Synopsis Throw an exception.
Syntax throw Exp
Description A throw statement causes the immediate abortion of the execution of the current function with Exp's value as exception value. The exception can be caught by a TryCatch statement in the current function or in one of its callers. If the exception is not caught, the execution of the Rascal program is terminated. The following rules apply:
  • The static type of Exp should be RuntimeException, see RuntimeException.
  • The Rascal program may contain data declarations that extend the type RuntimeException.
Examples Here is a a variant of string concatenation for ball haters:
rascal>str conc(str x, str y){ if("ball" in {x, y}) throw "I hate balls"; return x + y; }
str (str, str): str conc(str, str);
rascal>conc("fairy", "tale");
str: "fairytale"
rascal>conc("foot", "ball");
|stdin:///|(51,14,<1,51>,<1,65>): "I hate balls"
	at conc(|stdin:///|(24,43,<1,24>,<1,67>))
	at ___SCREEN_INSTANCE___(|stdin:///|(0,21,<1,0>,<1,21>))


Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.