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

  • Guard the function or operation with a test on the empty map (Rascal:isEmpty) and take alternative action in that case.
  • Catch the EmptyMap yourself, see Rascal:TryCatch.
Examples Import the Map library and introduce M with an empty map as value:
rascal>import Map;
rascal>M = ();
map[void, void]: ()
Trying to get an arbitrary value from it gives an error:
|rascal://Map|(1888,389,<92,0>,<107,43>): EmptyMap()
	at *** somewhere ***(|rascal://Map|(1888,389,<92,0>,<107,43>))
	at getOneFrom(|stdin:///|(11,1,<1,11>,<1,12>))

We can also catch the EmptyMap error. First import the Rascal exceptions (which are also included in Prelude) and IO:
rascal>import Exception;
rascal>import IO;
rascal>try println(getOneFrom(M)); catch EmptyMap(): println("Cannot use getOneFrom on empty map");
Cannot use getOneFrom on empty map
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