Error handling in dart
An exception is an error that takes place inside the
program. When an exception occurs inside a program
the normal flow of the program is disrupted and it
terminates abnormally, displaying the error and
exception stack as output. So, an exception must be
taken care to prevent the application from
termination.
Example1:
void main() {
String geek = "GeeksForGeeks";
try{
var geek2 = geek ~/ 0;
print(geek2);
}
on FormatException{
print("Error!! \nCan't act as input is not an integer.");
}
}
Example2:
void main() {
String geek = "GeeksForGeeks";
try{
var geek2 = geek ~/ 0;
print(geek2); catch(e); print(e); }}