'DartPad Not Supporting ON Clause
Solution 1:[1]
The issue here is that dart2js, which DartPad is based on, does not throw an IntegerDivisionByZeroException
(which should really be named DivisionByZeroError
, but alas, isn't) when you do integer division by zero.
It throws, but it's using UnsupportedError
instead, which is otherwise a good choice for such an error.
Dart2js is not wrong. Neither the language specification, nor the library documentation for num.~/
says that it should throw that particular error type. Still, it's inconsistent with the other compilers, so we may want to make it consisent.
Solution 2:[2]
You can simply try replacing the error received with IntegerDivisionByZeroException with the error found i.e,
void main(){
try {
int result = 12 ~/ 0;
print (result);
} on UnsupportedError { print("hua solve"); }
finally { print("cool!"); }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | lrn |
Solution 2 | Mayur Agarwal |