-
Notifications
You must be signed in to change notification settings - Fork 0
/
h2.txt
110 lines (99 loc) · 2.19 KB
/
h2.txt
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Problem 1
(a) "main begin", "main caught ex1", "main finally", "main end"
(b) "Program Terminated due to Exception Ex3"
(c) "Program Terminated due to Exception Ex3"
(d) "main being", "a begin", "b begin", "b finally", "a caught Ex2, "a end", "c begin", "c caught Ex2", "c finally", "c end", "main finally", "main end"
(e)
void main( )
{
println("main begin");
try {
a();
c();
} catch (Ex1 ex) {
println("main caught Ex1");
} catch (Ex3 ex) {
println("main caught Ex3");
} finally {
println("main finally");
}
println("main end");
}
void a( ) {
println("a begin");
try {
if (var1){
b();
}
else{
throw new Ex1();
}
} catch (Ex2 ex) {
println("a caught Ex2");
} catch (Ex3 ex) {
println("a caught Ex3");
}
println("a end");
}
void b( ) {
println("b begin");
try {
if (var2){
c();
}
else{
throw new Ex2();
}
} catch (Ex3 ex) {
println("b caught Ex3");
} finally {
println("b finally");
}
println("b end");
}
void c( ) {
println("c begin");
try {
if (var3){
throw new Ex2();
}
else{
throw new Ex3();
}
} catch (Ex2 ex) {
println("c caught Ex2");
} finally {
println("c finally");
}
println("c end");
}
Problem 2
public void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
filePath = Scanner.nextLine();
while (1)
{
try {
FileStream file(filePath);
Memory mem;
mem.allocate(file.length());
mem.read(file);
file.close();
break;
}
catch (FileNotExistException ex) {
System.out.println("Cannot open file. Enter file path again.");
filePath = Scanner.nextLine();
}
catch (FileCloseFailedError ex) {
System.out.println("Cannot close file.");
}
catch (MemoryAllocationFailedError ex) {
System.out.println("Cannot allocate enough memory.");
}
catch (ReadFailedException ex) {
System.out.println("Cannot read file into memory.");
}
}
}