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) Expressions().eval(cleanInput)
} catch (e: Exception) { } catch (e: Exception) {
when (e) { when (e) {
// Invalid expression, don't do anything
is ArrayIndexOutOfBoundsException, is ArrayIndexOutOfBoundsException,
is IndexOutOfBoundsException, is IndexOutOfBoundsException,
is NumberFormatException, is ExpressionException -> return
is ExpressionException, // Divide by zero or SQRT of negative
is ArithmeticException -> return is NumberFormatException, is ArithmeticException -> {
_calculated.update { null }
_result.update { "" }
return
}
else -> throw e else -> throw e
} }
} }