-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathexception_handling.dart
More file actions
42 lines (38 loc) · 1.28 KB
/
exception_handling.dart
File metadata and controls
42 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//Built-in Dart exceptions include
//1. DeferredLoadException: Thrown when a deferred library fails to load.
//2. FormatException: Exception thrown when a string or some other data does not have an expected format and cannot be parsed or processed.
//3. IntegerDivisionByZeroException: // Thrown when a number is divided by zero.
//4. IOException: Base class for all Inupt-Output related exceptions.
//5. IsolateSpawnException: Thrown when an isolate cannot be created.
//6. Timeout: Thrown when a scheduled timeout happens while waiting for an async result.
main() {
int x = 12;
int y = 0;
int res;
print("1) try / on statement");
try {
res = x ~/ y; // ~/ => truncating division operator, always returns a int value.
}
on IntegerDivisionByZeroException {
print('Exception:: Cannot divide by zero');
}
print("2) try / on / catch statement");
try {
res = x ~/ y;
}
on IntegerDivisionByZeroException catch(e) {
print(e);
print('Exception:: Cannot divide by zero');
}
print("3) try / on / catch / finally statement");
try {
res = x ~/ y;
}
on IntegerDivisionByZeroException catch(e) {
print(e);
print('Exception:: Cannot divide by zero');
}
finally{
print("Finally block: always execute => no matter if there is execption or not.");
}
}