Catch divide by zero and sqrt of negative exceptions

This commit is contained in:
Sad Ellie 2023-01-13 18:58:24 +04:00
parent 02bf4a8497
commit c72316acf1

View File

@ -436,11 +436,16 @@ class MainViewModel @Inject constructor(
Expressions().eval(cleanInput)
} catch (e: Exception) {
when (e) {
// Invalid expression, don't do anything
is ArrayIndexOutOfBoundsException,
is IndexOutOfBoundsException,
is NumberFormatException,
is ExpressionException,
is ArithmeticException -> return
is ExpressionException -> return
// Divide by zero or SQRT of negative
is NumberFormatException, is ArithmeticException -> {
_calculated.update { null }
_result.update { "" }
return
}
else -> throw e
}
}