-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFinallyWorks.java
More file actions
44 lines (37 loc) · 936 Bytes
/
FinallyWorks.java
File metadata and controls
44 lines (37 loc) · 936 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
package exceptions;
/**
* RUN:
* javac exceptions/FinallyWorks.java && java exceptions.FinallyWorks
* OUTPUT:
* ThreeException
* finally scope
* No exception
* finally scope
*/
// import java.util.logging.*;
// import java.io.*;
public class FinallyWorks {
static int count = 0;
public static void main(String[] args)
{
while(true)
{
try {
if (count++ == 0) {
throw new ThreeException();
}
System.out.println("No exception");
}
catch(ThreeException e) {
System.out.println("ThreeException");
}
finally {
System.out.println("finally scope");
if (count == 2) {
break;
}
}
}
}
}
class ThreeException extends Exception {}