-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.dart
More file actions
38 lines (34 loc) · 764 Bytes
/
exception.dart
File metadata and controls
38 lines (34 loc) · 764 Bytes
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
//Exception handling
int mustGreaterThanZero(int val) {
if (val <= 0) {
throw Exception("Value must be greater than zero");
}
return val;
}
void letVerifyTheValue(var val) {
var valueVerification;
try {
valueVerification = mustGreaterThanZero(val);
} catch (e) {
print(e);
} finally {
if (valueVerification == null) {
print("Value is not accepted");
} else {
print("Value verified: $valueVerification");
}
}
}
void main(List<String> args) {
letVerifyTheValue(10);
letVerifyTheValue(0);
}
//To catch particular errors use on keyword instead of catch for example;
/*on OutOfLlamasException{
buyMoreLlamas();
}
on Exception catch(e){
//Anything else that is an exception
print("Uknown exception: $e");
}
*/