Exception_Dart
import "dart:io";
// void main() {
// try {
// checkage(10);
// } catch(e) {
// print(e);
// }
// }
// void checkage(int age) {
// if(age < 18) {
// throw new FormatException("This is not Eligible");
// }
// }
//Example 1
// void main() {
// int x = 12;
// int y = 0;
// int ans;
//
// try {
// ans = x ~/ y;
// } catch(e) {
// print(e);
// }
// }
//Example 2
// void main() {
// var no1 = 10, no2 = 0, no3 = 0;
//
// no3 = no1 ~/ no2; //1st Method to indicate
// no3 = (no1 / no2) as int; //2nd Method to indicate
// print(no3);
// }
//Example 3
// void main() {
// //Program 1:
// // double no1 = 10;
// // double no2 = 0;
// // double no3 = 0;
// // no3 = no1/no2;
// // print(no3); //OUTPUT : Infinity
// //
// //Program 2 :
// //Here below in this case program will stop
// // int no4 = 10;
// // int no5 = 0;
// // int no6 = 0;
// // no6 = no4 ~/ no5;
// // print(no6); //OUTPUT : Unhandled exception: IntegerDivisionByZeroException
// // print("Continue");//This will not print OR Execute statement because program execution will stop
//
// //Program 3 :
// //Here below in this case,program will break and will continue next upcoming task Execution performing
// try {
// int no4 = 10;
// int no5 = 0;
// int no6 = 0;
// no6 = no4 ~/ no5;
// print(no6);
// } catch(e)
// { //OUTPUT : IntegerDivisionByZeroException
// print(e);
// }
// print("Continue...rest of the Tasks performing...");
//
//
// }
//Example 4
void main() {
//Program 1
// try {
// int no1 = 10;
// int no2 = 0;
// int no3 = 0;
// no3 = no1 ~/ no2;
// } catch(e) {
// print(e);
// }
//Program 2
try {
int no1 = 10;
int no2 = 0;
int no3 = 0;
no3 = no1 ~/ no2;
}
// ignore: deprecated_member_use
on IntegerDivisionByZeroException {
print("Value can not divide by Zero");
}
finally {
print("Finally message called");
}
print("Continue...rest of the Tasks performing...");
}
Comments
Post a Comment