For all the peeps who are facing error in dartpad 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. or simply try replacing the error recieved with IntegerDivisionByZeroException with the error found i.e void main(){ try { int result = 12 ~/ 0; print (result); } on UnsupportedError { print("hogaya solve"); }finally{ print("cool"); } }
Hats off man! Absolutely well presented! The content just flows. Your ability to compress key concepts so well and clearly is just amazing! Thanks for this work.
void main() { try { int x =12 ~/ 0; print("the result is $x"); } on IntegerDivisionByZeroException { print("cannot devide by zero"); } } // gives me this type of error Uncaught exception: Unsupported operation: Result of truncating division is Infinity: 12 ~/ 0 its mean exception is not handled by the on clause?
Its really a great effort....! Thanks a lot! Meanwhile when i tried following code, //exception handling using by clause void main(){ try { int i= 12 ~/ 0; print (i); } on IntegerDivisionByZeroException { print ("number can not be divided by zero"); } } It throws this error "Error: Unsupported operation: Result of truncating division is Infinity: 12 ~/ 0". Can you please explain?
Thank you so much for your videos, you're a natural born teacher! About handling Exceptions, when I test code in DartPad, I just get this message in the console "Script error". I'd like to test in Android studio to get full error messages, but I don't know how to run code directly in the console, without an emulator. Anyone could help me? Cheers
Hi, Hope you have found the solution, if not consider trying this stackoverflow.com/questions/53888000/how-to-run-dart-in-android-studio/53888108 For practicing dart you can consider using Visual Studio Code instead of Android studio.