DartLang

🎯 Dart (DartLang) Introduction: Exception handling

An exception is an error occurred at runtime because Dart runtime could not execute a statement successfully or any other thousand reasons.

Uday Hiwarale
RunDart
Published in
3 min readOct 6, 2019

--

An exception is an error occurred at runtime because Dart runtime could not execute a statement successfully or any other thousand reasons. When an exception is thrown, there is a good chance that our program will crash.

To save our program from crashing, we need to catch an exception. This is done using try/catch/finally block you might already be familiar with. Let’s take a classical example of dividing a number by zero.

A division of a number by zero raises IntegerDivisionByZeroException exception and we caught it inside catch block. Fun fact, normal division using / operator does not raise an exception, instead, it returns Infinity.

--

--