-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy patherror_handle.ai
More file actions
48 lines (40 loc) · 745 Bytes
/
error_handle.ai
File metadata and controls
48 lines (40 loc) · 745 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
39
40
41
42
43
44
45
46
47
48
// class FileNotFound! {
// name: str,
// }
// print(FileNotFound!);
enum IOError! {
DiskFull = "the disk is fulled",
Interrupted = "io is interrupted",
}
// print(IOError!);
// fn check_error(e: IOError!) {
// print(e);
// }
// check_error(IOError!::DiskFull);
enum ArithError! {
DivideZero,
}
fn divide(a, b) -> int | ArithError! {
if b == 0 {
raise ArithError!::DivideZero;
}
return a / b;
}
fn do_math() {
let x = 0;
let v = divide(1, 0) |err| {
let a = 1;
print("error:", err);
999
};
print(v);
// let y = divide(1, 1)?;
// print(y);
}
let x = do_math();
print(x);
// {
// print(1);
// let a = IOError!::DiskFull;
// let x = a;
// }