mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 08:45: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)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user