
Evaluates mathematical expressions from strings into `Double` values, supporting customizable binary and unary operators, functions, and constants. Offers default settings and DSL for advanced customization. Handles errors with specific exceptions.
A Kotlin Multiplatform mini library for string evaluation
(You may need to watch out using it: having to evaluate a string into a number is more often than not a code smell)
You can import Keval directly with the jar files, or using your favorite dependency manager with the Maven Central repository:
Maven
<dependencies>
<dependency>
<groupId>com.notkamui.libs</groupId>
<artifactId>keval</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>Gradle (here with KotlinDSL)
repositories {
mavenCentral()
}
dependencies {
implementation("com.notkamui.libs:keval:2.1.0")
}(In case you're using it with another language than Kotlin -- i.e. Java --, make sure you include kotlin stdlib too)
Keval can evaluate a mathematical expression as a String into a Double value. It is customizable in the sense that
one can add new binary and unary operators, functions and constants.
The base settings of Keval already include sensible defaults for the most common mathematical operations.
Keval has support for all classic binary operators:
-
+
*
/
^
%
Keval has support for all classic unary operators:
- (prefix)+ (prefix) (basically does nothing)! (postfix)Keval has support for functions of variable arity:
neg(expr) (where 'expr' is an expression)sign(expr) (where 'expr' is an expression)abs(expr) (where 'expr' is an expression)sqrt(expr) (where 'expr' is an expression)cbrt(expr) (where 'expr' is an expression)nthrt(expr_a, expr_pow) (where 'expr_a' is an expression and 'expr_pow' is target power)exp(expr) (where 'expr' is an expression)ln(expr) (where 'expr' is an expression)log10(expr) (where 'expr' is an expression)log2(expr) (where 'expr' is an expression)sin(expr) (where 'expr' is an expression)cos(expr) (where 'expr' is an expression)tan(expr) (where 'expr' is an expression)asin(expr) (where 'expr' is an expression)acos(expr) (where 'expr' is an expression)atan(expr) (where 'expr' is an expression)ceil(expr) (where 'expr' is an expression)floor(expr) (where 'expr' is an expression)round(expr) (where 'expr' is an expression)trunc(expr) (where 'expr' is an expression)min(expr...)/max(expr...)/avg(expr...)/median(expr...) (where 'expr...' is any number of expressions to get results from)percentile(expr_perc, expr_a) (where 'expr_a' is the expression to get percentile from, and 'expr_perc' is the percent value)rand(expr...) (where 'expr...' is any number of expressions; either generates a random double (zero arguments), or generates a random integer up to expr (one argument), or selects a random value of given arguments (two or more arguments)randRange(expr_start, expr_end, expr_step)
bool(expr) (where 'expr' is an expression)not(bool) (where 'bool' is a boolean)and(bool...) (where 'bool...' is any number of booleans)nand(bool...) (where 'bool...' is any number of booleans)or(bool...) (where 'bool...' is any number of booleans)nor(bool...) (where 'bool...' is any number of booleans)xor(bool...) (where 'bool...' is any number of booleans)xnor(bool...) (where 'bool...' is any number of booleans)imply(bool_a, bool_b) (where 'bool_a' and 'bool_b' are booleans)nimply(bool_a, bool_b) (where 'bool_a' and 'bool_b' are booleans)eq(expr...) (where 'expr...' is any number of expressions; returns a boolean)ne(expr...) (where 'expr...' is any number of expressions; returns a boolean)gt(expr_a, expr_b) (where 'expr_a' and 'expr_b' are expressions; returns a boolean)ge(expr_a, expr_b) (where 'expr_a' and 'expr_b' are expressions; returns a boolean)lt(expr_a, expr_b) (where 'expr_a' and 'expr_b' are expressions; returns a boolean)le(expr_a, expr_b) (where 'expr_a' and 'expr_b' are expressions; returns a boolean)Keval has support for constants; it has two built-in constants:
PI
e (Euler's number)You can optionally add as many operators, functions or constants to Keval, as long as you define every field properly, with a DSL (Domain Specific Language):
Char that is NOT a digit, nor a letter, nor an underscore)Int)Boolean true if left associative, false otherwise)(N, N) -> N)Char that is NOT a digit, nor a letter, nor an underscore)Boolean)(N) -> N)String identifier, that doesn't start with a digit, and only contains letters, digits or
underscores)Int or null if the function can take any number of arguments,
also called a variadic function)(List<N>) -> N)String identifier, that doesn't start with a digit, and only contains letters, digits or
underscores)N)Keval will use the built-in operators, function and constants if you choose not to define any new resource ; but if you choose to do so, you need to include them manually. You may also choose to use Keval as an extension function.
Please note that adding a new resource with a name that already exists will overwrite the previous one, except in the case of operators, where one symbol can represent both a binary and a unary operator. For example, it is possible to define a binary operator
-and a unary operator-at the same time.
You can use it in several ways:
Keval.eval("(3+4)(2/8 * 5) % PI") // uses default resources
"(3+4)(2/8 * 5) % PI".keval() // extension ; uses default resources
Keval.create(KevalNumbers.real) { // builder instance
includeDefault() // this function includes the built-in resources
binaryOperator { // this function adds a binary operator ; you can call it several times
symbol = ';'
precedence = 3
isLeftAssociative = true
implementation = { a, b -> a.pow(2) + b.pow(2) }
}
unaryOperator { // this function adds a unary operator ; you can call it several times
symbol = '#'
isPrefix = false
implementation = { arg -> (1..arg.toInt()).fold(0.0) { acc, i -> acc + i } }
}
function { // this function adds a function ; you can call it several times
name = "max"
arity = 2
implementation = { args -> max(args[0], args[1]) }
}
function { // this function adds a variadic aggregation (no arity) ; you can call it several times
name = "sum"
implementation = { args -> args.sum() }
}
constant { // this function adds a constant ; you can call it several times
name = "PHI"
value = 1.618
}
}.eval("2*max(2, 3) ; 4# + PHI^2")
"2*max(2, 3) ; 4# + PHI^2".keval { // builder instance + extension
includeDefault()
binaryOperator {
symbol = ';'
precedence = 3
isLeftAssociative = true
implementation = { a, b -> a.pow(2) + b.pow(2) }
}
unaryOperator {
symbol = '#'
isPrefix = false
implementation = { arg -> (1..arg.toInt()).fold(0.0) { acc, i -> acc + i } }
}
function {
name = "max"
arity = 2
implementation = { args -> max(args[0], args[1]) }
}
function {
name = "sum"
implementation = { args -> args.sum() }
}
constant {
name = "PHI"
value = 1.618
}
}The advantage of using Keval.create is that you may keep an instance of it in a variable so that you can call as
many eval as you need.
In concordance with creating a Keval instance, you can also add resources like this:
val kvl = Keval.create(KevalNumbers.real) { includeDefault() }
.withBinaryOperator( // includes a new binary operator
';', // symbol
3, // precedence
true // isLeftAssociative
) { a, b -> a.pow(2) + b.pow(2) } // implementation
.withUnaryOperator( // includes a new unary operator
'#', // symbol
false, // isPrefix
) { arg -> (1..arg.toInt()).fold(0.0) { acc, i -> acc + i } } // implementation
.withFunction( // includes a new function
"max", // name
2 // arity
) { max(it[0], it[1]) } // implementation
.withFunction( // includes a new variadic function
"sum", // name
) { it.sum() } // implementation
.withConstant( // includes a new constant
"PHI", // name
1.618 // value
)
kvl.eval("2*max(2, 3) ; 4# + PHI^2")This can be combined with creating an instance with a DSL (i.e. Keval.create).
This is an especially useful syntax for Java users, since DSLs generally don't translate well over it.
Creating a resource with a name that already exists will overwrite the previous one.
Keval assumes products/multiplications, and as such, the * symbol/name cannot be overwritten, and is the only operator to always be present in the resource set of a Keval instance:
"(2+3)(6+4)".keval() == "(2+3)*(6+4)".keval()In addition, the symbols (,),, are reserved and trying to create operator using one of those symbols will result with an exception.
By default Keval evaluates to Double (KevalNumbers.real on every platform). You can evaluate to another numeric type by implementing KevalNumber<N> and passing it to Keval.create, evalWith, or compileWith:
Keval.create(myNumber) {
includeDefault()
function {
name = "twice"
arity = 1
implementation = { args -> args[0] + args[0] }
}
}.eval("twice(21)")
"1 + 2".evalWith(KevalNumbers.real)
val compiled = "x * 2".compileWith(KevalNumbers.real)String.keval() and Keval.eval(String) remain convenient Double-only shortcuts.
includeDefault() loads whatever your type returns from defaultResources(). Define those defaults with kevalResources, using the same DSL as Keval.create:
object MyLongs : KevalNumber<Long> {
override fun isValidLiteral(token: String) = token.toLongOrNull() != null
override fun parseLiteral(token: String) = token.toLong()
override fun multiply(a: Long, b: Long) = a * b
override fun defaultResources() = kevalResources {
binaryOperator {
symbol = '+'
precedence = 2
isLeftAssociative = true
implementation = Long::plus
}
unaryOperator {
symbol = '+'
isPrefix = true
implementation = { it }
}
// binaryOperator / unaryOperator / function / constant as needed
}
}
Keval.create(MyLongs) { includeDefault() }.eval("1 + 2") // 3
MyLongs.eval("10 + 5") // 15Define multiply for * and for implicit products such as (2)(3). You do not register * in defaultResources().
When you evaluate the same expression repeatedly, compile it once:
val keval = Keval.create(KevalNumbers.real) { includeDefault() }
val expr = keval.compile("2 + rate * hours")
expr.eval(mapOf("rate" to 25.0, "hours" to 8.0)) // 202.0
expr.variables // setOf("rate", "hours")You can also use "...".compileWith(KevalNumbers.real).
Names that are not operators, functions, or constants are variables. Pass bindings to eval; constants and functions win if the name collides.
val keval = Keval.create(KevalNumbers.real) { includeDefault() }
keval.eval("x + y", mapOf("x" to 3.0, "y" to 7.0)) // 10.0
keval.compile("x(y + 1)").eval(mapOf("x" to 2.0, "y" to 2.0)) // 6.0 (implicit *)A missing binding throws KevalUnresolvedVariableException.
Prefer evalOrNull / evalResult (or String.kevalOrNull() / String.kevalResult() for Double) when you do not want to catch KevalException yourself. These only treat Keval errors as failure: other throwables still propagate.
On the JVM, use KevalNumbers.BigDecimal for exact decimal arithmetic. Built-ins cover arithmetic, comparisons, aggregates, and rounding (not trig, log, or random). Comparisons such as eq / ne treat values by numeric equality (1.0 and 1.00 are equal).
"0.1 + 0.2".kevalBigDecimal() // BigDecimal("0.3")
Keval.create(KevalNumbers.BigDecimal) {
includeDefault()
}.eval("sum(1, 2, 3)")
val lowPrecision = KevalNumberBigDecimal.withContext(MathContext(4))
Keval.create(lowPrecision) { includeDefault() }.eval("1 / 3") // 0.3333KevalNumbers.BigDecimal is not available on Android. Use KevalNumbers.real for Double, or ship your own KevalNumber<BigDecimal> with kevalResources (you can mirror the JVM BigDecimal defaults).
| v1.x | v2.x |
|---|---|
Keval.create { includeDefault() } |
Keval.create(KevalNumbers.real) { includeDefault() } |
(Double, Double) -> Double operators |
(N, N) -> N |
(DoubleArray) -> Double functions |
(List<N>) -> N |
KevalBuilder.DEFAULT_RESOURCES |
KevalNumbers.real.defaultResources() |
String.keval() and Keval.eval(expr) are unchanged for Double.
In case of an error, Keval will throw one of several KevalExceptions:
KevalZeroDivisionException in the case a zero division occursKevalInvalidArgumentException in the case a operator or function is called with an invalid argument (i.e. a negative number
for a factorial)KevalInvalidExpressionException if the expression is invalid (includes malformed syntax), with the following properties:
expression contains the fully sanitized expressionposition is an estimate of the position of the errorKevalInvalidSymbolException if the expression contains an invalid operator, with the following properties:
invalidSymbol contains the actual invalid operatorexpression contains the fully sanitized expressionposition is an estimate of the position of the errorKevalUnresolvedVariableException if a variable is used without a bindingKevalDSLException if, in the DSL, one of the field is either not set, or doesn't follow its restrictions (defined
above)KevalZeroDivisionException, KevalInvalidArgumentException, and KevalUnresolvedVariableException are instantiable so that you can throw them when implementing a custom operator/function.
Use evalOrNull / evalResult (or String.kevalOrNull() / String.kevalResult() for Double) when you prefer not to catch exceptions manually.
A Kotlin Multiplatform mini library for string evaluation
(You may need to watch out using it: having to evaluate a string into a number is more often than not a code smell)
You can import Keval directly with the jar files, or using your favorite dependency manager with the Maven Central repository:
Maven
<dependencies>
<dependency>
<groupId>com.notkamui.libs</groupId>
<artifactId>keval</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>Gradle (here with KotlinDSL)
repositories {
mavenCentral()
}
dependencies {
implementation("com.notkamui.libs:keval:2.1.0")
}(In case you're using it with another language than Kotlin -- i.e. Java --, make sure you include kotlin stdlib too)
Keval can evaluate a mathematical expression as a String into a Double value. It is customizable in the sense that
one can add new binary and unary operators, functions and constants.
The base settings of Keval already include sensible defaults for the most common mathematical operations.
Keval has support for all classic binary operators:
-
+
*
/
^
%
Keval has support for all classic unary operators:
- (prefix)+ (prefix) (basically does nothing)! (postfix)Keval has support for functions of variable arity:
neg(expr) (where 'expr' is an expression)sign(expr) (where 'expr' is an expression)abs(expr) (where 'expr' is an expression)sqrt(expr) (where 'expr' is an expression)cbrt(expr) (where 'expr' is an expression)nthrt(expr_a, expr_pow) (where 'expr_a' is an expression and 'expr_pow' is target power)exp(expr) (where 'expr' is an expression)ln(expr) (where 'expr' is an expression)log10(expr) (where 'expr' is an expression)log2(expr) (where 'expr' is an expression)sin(expr) (where 'expr' is an expression)cos(expr) (where 'expr' is an expression)tan(expr) (where 'expr' is an expression)asin(expr) (where 'expr' is an expression)acos(expr) (where 'expr' is an expression)atan(expr) (where 'expr' is an expression)ceil(expr) (where 'expr' is an expression)floor(expr) (where 'expr' is an expression)round(expr) (where 'expr' is an expression)trunc(expr) (where 'expr' is an expression)min(expr...)/max(expr...)/avg(expr...)/median(expr...) (where 'expr...' is any number of expressions to get results from)percentile(expr_perc, expr_a) (where 'expr_a' is the expression to get percentile from, and 'expr_perc' is the percent value)rand(expr...) (where 'expr...' is any number of expressions; either generates a random double (zero arguments), or generates a random integer up to expr (one argument), or selects a random value of given arguments (two or more arguments)randRange(expr_start, expr_end, expr_step)
bool(expr) (where 'expr' is an expression)not(bool) (where 'bool' is a boolean)and(bool...) (where 'bool...' is any number of booleans)nand(bool...) (where 'bool...' is any number of booleans)or(bool...) (where 'bool...' is any number of booleans)nor(bool...) (where 'bool...' is any number of booleans)xor(bool...) (where 'bool...' is any number of booleans)xnor(bool...) (where 'bool...' is any number of booleans)imply(bool_a, bool_b) (where 'bool_a' and 'bool_b' are booleans)nimply(bool_a, bool_b) (where 'bool_a' and 'bool_b' are booleans)eq(expr...) (where 'expr...' is any number of expressions; returns a boolean)ne(expr...) (where 'expr...' is any number of expressions; returns a boolean)gt(expr_a, expr_b) (where 'expr_a' and 'expr_b' are expressions; returns a boolean)ge(expr_a, expr_b) (where 'expr_a' and 'expr_b' are expressions; returns a boolean)lt(expr_a, expr_b) (where 'expr_a' and 'expr_b' are expressions; returns a boolean)le(expr_a, expr_b) (where 'expr_a' and 'expr_b' are expressions; returns a boolean)Keval has support for constants; it has two built-in constants:
PI
e (Euler's number)You can optionally add as many operators, functions or constants to Keval, as long as you define every field properly, with a DSL (Domain Specific Language):
Char that is NOT a digit, nor a letter, nor an underscore)Int)Boolean true if left associative, false otherwise)(N, N) -> N)Char that is NOT a digit, nor a letter, nor an underscore)Boolean)(N) -> N)String identifier, that doesn't start with a digit, and only contains letters, digits or
underscores)Int or null if the function can take any number of arguments,
also called a variadic function)(List<N>) -> N)String identifier, that doesn't start with a digit, and only contains letters, digits or
underscores)N)Keval will use the built-in operators, function and constants if you choose not to define any new resource ; but if you choose to do so, you need to include them manually. You may also choose to use Keval as an extension function.
Please note that adding a new resource with a name that already exists will overwrite the previous one, except in the case of operators, where one symbol can represent both a binary and a unary operator. For example, it is possible to define a binary operator
-and a unary operator-at the same time.
You can use it in several ways:
Keval.eval("(3+4)(2/8 * 5) % PI") // uses default resources
"(3+4)(2/8 * 5) % PI".keval() // extension ; uses default resources
Keval.create(KevalNumbers.real) { // builder instance
includeDefault() // this function includes the built-in resources
binaryOperator { // this function adds a binary operator ; you can call it several times
symbol = ';'
precedence = 3
isLeftAssociative = true
implementation = { a, b -> a.pow(2) + b.pow(2) }
}
unaryOperator { // this function adds a unary operator ; you can call it several times
symbol = '#'
isPrefix = false
implementation = { arg -> (1..arg.toInt()).fold(0.0) { acc, i -> acc + i } }
}
function { // this function adds a function ; you can call it several times
name = "max"
arity = 2
implementation = { args -> max(args[0], args[1]) }
}
function { // this function adds a variadic aggregation (no arity) ; you can call it several times
name = "sum"
implementation = { args -> args.sum() }
}
constant { // this function adds a constant ; you can call it several times
name = "PHI"
value = 1.618
}
}.eval("2*max(2, 3) ; 4# + PHI^2")
"2*max(2, 3) ; 4# + PHI^2".keval { // builder instance + extension
includeDefault()
binaryOperator {
symbol = ';'
precedence = 3
isLeftAssociative = true
implementation = { a, b -> a.pow(2) + b.pow(2) }
}
unaryOperator {
symbol = '#'
isPrefix = false
implementation = { arg -> (1..arg.toInt()).fold(0.0) { acc, i -> acc + i } }
}
function {
name = "max"
arity = 2
implementation = { args -> max(args[0], args[1]) }
}
function {
name = "sum"
implementation = { args -> args.sum() }
}
constant {
name = "PHI"
value = 1.618
}
}The advantage of using Keval.create is that you may keep an instance of it in a variable so that you can call as
many eval as you need.
In concordance with creating a Keval instance, you can also add resources like this:
val kvl = Keval.create(KevalNumbers.real) { includeDefault() }
.withBinaryOperator( // includes a new binary operator
';', // symbol
3, // precedence
true // isLeftAssociative
) { a, b -> a.pow(2) + b.pow(2) } // implementation
.withUnaryOperator( // includes a new unary operator
'#', // symbol
false, // isPrefix
) { arg -> (1..arg.toInt()).fold(0.0) { acc, i -> acc + i } } // implementation
.withFunction( // includes a new function
"max", // name
2 // arity
) { max(it[0], it[1]) } // implementation
.withFunction( // includes a new variadic function
"sum", // name
) { it.sum() } // implementation
.withConstant( // includes a new constant
"PHI", // name
1.618 // value
)
kvl.eval("2*max(2, 3) ; 4# + PHI^2")This can be combined with creating an instance with a DSL (i.e. Keval.create).
This is an especially useful syntax for Java users, since DSLs generally don't translate well over it.
Creating a resource with a name that already exists will overwrite the previous one.
Keval assumes products/multiplications, and as such, the * symbol/name cannot be overwritten, and is the only operator to always be present in the resource set of a Keval instance:
"(2+3)(6+4)".keval() == "(2+3)*(6+4)".keval()In addition, the symbols (,),, are reserved and trying to create operator using one of those symbols will result with an exception.
By default Keval evaluates to Double (KevalNumbers.real on every platform). You can evaluate to another numeric type by implementing KevalNumber<N> and passing it to Keval.create, evalWith, or compileWith:
Keval.create(myNumber) {
includeDefault()
function {
name = "twice"
arity = 1
implementation = { args -> args[0] + args[0] }
}
}.eval("twice(21)")
"1 + 2".evalWith(KevalNumbers.real)
val compiled = "x * 2".compileWith(KevalNumbers.real)String.keval() and Keval.eval(String) remain convenient Double-only shortcuts.
includeDefault() loads whatever your type returns from defaultResources(). Define those defaults with kevalResources, using the same DSL as Keval.create:
object MyLongs : KevalNumber<Long> {
override fun isValidLiteral(token: String) = token.toLongOrNull() != null
override fun parseLiteral(token: String) = token.toLong()
override fun multiply(a: Long, b: Long) = a * b
override fun defaultResources() = kevalResources {
binaryOperator {
symbol = '+'
precedence = 2
isLeftAssociative = true
implementation = Long::plus
}
unaryOperator {
symbol = '+'
isPrefix = true
implementation = { it }
}
// binaryOperator / unaryOperator / function / constant as needed
}
}
Keval.create(MyLongs) { includeDefault() }.eval("1 + 2") // 3
MyLongs.eval("10 + 5") // 15Define multiply for * and for implicit products such as (2)(3). You do not register * in defaultResources().
When you evaluate the same expression repeatedly, compile it once:
val keval = Keval.create(KevalNumbers.real) { includeDefault() }
val expr = keval.compile("2 + rate * hours")
expr.eval(mapOf("rate" to 25.0, "hours" to 8.0)) // 202.0
expr.variables // setOf("rate", "hours")You can also use "...".compileWith(KevalNumbers.real).
Names that are not operators, functions, or constants are variables. Pass bindings to eval; constants and functions win if the name collides.
val keval = Keval.create(KevalNumbers.real) { includeDefault() }
keval.eval("x + y", mapOf("x" to 3.0, "y" to 7.0)) // 10.0
keval.compile("x(y + 1)").eval(mapOf("x" to 2.0, "y" to 2.0)) // 6.0 (implicit *)A missing binding throws KevalUnresolvedVariableException.
Prefer evalOrNull / evalResult (or String.kevalOrNull() / String.kevalResult() for Double) when you do not want to catch KevalException yourself. These only treat Keval errors as failure: other throwables still propagate.
On the JVM, use KevalNumbers.BigDecimal for exact decimal arithmetic. Built-ins cover arithmetic, comparisons, aggregates, and rounding (not trig, log, or random). Comparisons such as eq / ne treat values by numeric equality (1.0 and 1.00 are equal).
"0.1 + 0.2".kevalBigDecimal() // BigDecimal("0.3")
Keval.create(KevalNumbers.BigDecimal) {
includeDefault()
}.eval("sum(1, 2, 3)")
val lowPrecision = KevalNumberBigDecimal.withContext(MathContext(4))
Keval.create(lowPrecision) { includeDefault() }.eval("1 / 3") // 0.3333KevalNumbers.BigDecimal is not available on Android. Use KevalNumbers.real for Double, or ship your own KevalNumber<BigDecimal> with kevalResources (you can mirror the JVM BigDecimal defaults).
| v1.x | v2.x |
|---|---|
Keval.create { includeDefault() } |
Keval.create(KevalNumbers.real) { includeDefault() } |
(Double, Double) -> Double operators |
(N, N) -> N |
(DoubleArray) -> Double functions |
(List<N>) -> N |
KevalBuilder.DEFAULT_RESOURCES |
KevalNumbers.real.defaultResources() |
String.keval() and Keval.eval(expr) are unchanged for Double.
In case of an error, Keval will throw one of several KevalExceptions:
KevalZeroDivisionException in the case a zero division occursKevalInvalidArgumentException in the case a operator or function is called with an invalid argument (i.e. a negative number
for a factorial)KevalInvalidExpressionException if the expression is invalid (includes malformed syntax), with the following properties:
expression contains the fully sanitized expressionposition is an estimate of the position of the errorKevalInvalidSymbolException if the expression contains an invalid operator, with the following properties:
invalidSymbol contains the actual invalid operatorexpression contains the fully sanitized expressionposition is an estimate of the position of the errorKevalUnresolvedVariableException if a variable is used without a bindingKevalDSLException if, in the DSL, one of the field is either not set, or doesn't follow its restrictions (defined
above)KevalZeroDivisionException, KevalInvalidArgumentException, and KevalUnresolvedVariableException are instantiable so that you can throw them when implementing a custom operator/function.
Use evalOrNull / evalResult (or String.kevalOrNull() / String.kevalResult() for Double) when you prefer not to catch exceptions manually.