Synopsis Illegal operation on an empty set.
Function data RunTimeException = EmptyMap();
Usage import Exception;
Description Rascal provides many operations and functions on sets, see Rascal:Values/Set and Rascal:Prelude/Set. This error is generated when a function or operations cannot handle the empty set.

  • Guard the function or operation with a test on the empty set (Rascal:isEmpty) and take alternative action in that case.
  • Catch the EmptySet yourself, see Rascal:TryCatch.
Examples Import the Set library and introduce S with an empty set as value:
rascal>import Set;
rascal>S = {};
set[void]: {}
Taking an element from an empty set gives an error:
|rascal://Set|(1712,454,<52,0>,<76,54>): EmptySet()
	at *** somewhere ***(|rascal://Set|(1712,454,<52,0>,<76,54>))
	at getOneFrom(|stdin:///|(11,1,<1,11>,<1,12>))

We can also catch the EmptySet error. First import the Rascal exceptions (which are also included in Prelude) and IO:
rascal>import Exception;
rascal>import IO;
rascal>try println(getOneFrom(S)); catch EmptySet(): println("Cannot apply getOneFrom to empty set");
Cannot apply getOneFrom to empty set
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