I have something like this in my app:
def something(x: Int, y: Int) Z {
(x / y)
}
Now, if the someval is not a number (meaning that either x or y is equal to 0), then I'd like Z to just become 0 instead of displaying an error ([ArithmeticException: Division by zero]
)
I know I can do:
Try(someVale) orElse Try(0)
However, that'll give me Success(0)
whereas I'd just like for it to give me a 0
in that case.
Maybe there's something like if ArithmeticException then 0
in Scala or something to remove the "Success" and parenthesis. Can someone shed some light please?