As a good programmer, you test your app in all possible conditions. Dart defines a number of errors for those things that you should remedy in your code, such as CastError
when a cast fails, or NoSuchMethodError
when the class of the object on which the method is called does not have this method, and neither does any of its parent classes. All these are subclasses of the Error
class, and you should code so that they do not occur. However, when something unexpected occurs while running the app and the code cannot cope with it, Unhandled Exception
occurs. Especially, the input values that are read in from the keyboard, a file, or a network connection are dangerous. Suppose the input is such a value that is supposed to be an integer (refer to exceptions.dart
); we try to convert it into an int
type in line (1)
:
var input = "47B9"; // value read from input, // should be an integer int inp = int.parse(input); (1)
While running the program...