mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
Catch divide by zero and sqrt of negative exceptions
This commit is contained in:
parent
02bf4a8497
commit
c72316acf1
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user