Empty Set
rascal-0.40.17
Synopsis
Illegal operation on an empty set.
Types
data RuntimeException = EmptySet();
Usage
import Exception;
(only needed when EmptySet
is used in catch
)
Description
Rascal provides many operations and functions on sets, see set values and set functions. This error is generated when a function or operations cannot handle the empty set.
Remedies:
- Guard the function or operation with a test on the empty set (isEmpty) and take alternative action in that case.
- Catch the
EmptySet
yourself, see try catch.
Examples
Import the Set
library and introduce S
with an empty set as value:
rascal>import Set;
ok
rascal>S = {};
set[void]: {}
Taking an element from an empty set gives an error:
rascal>getOneFrom(S);
|jar+file:///home/runner/.m2/repository/org/rascalmpl/rascal/0.40.17/rascal-0.40.17.jar!/Set.rsc|(6272,1208,<273,0>,<303,38>): EmptySet()
at *** somewhere ***(|jar+file:///home/runner/.m2/repository/org/rascalmpl/rascal/0.40.17/rascal-0.40.17.jar!/Set.rsc|(6272,1208,<273,0>,<303,38>))
at getOneFrom(|prompt:///|(11,1,<1,11>,<1,12>))
ok
We can also catch the EmptySet
error. First import the Rascal exceptions (which are also included in Prelude
)
and IO
:
rascal>import Exception;
ok
rascal>import IO;
ok
rascal>try
>>>>>>> println(getOneFrom(S));
>>>>>>>catch EmptySet():
>>>>>>> println("Cannot apply getOneFrom to empty set");
Cannot apply getOneFrom to empty set
ok