-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloseable.java
More file actions
27 lines (22 loc) · 749 Bytes
/
Closeable.java
File metadata and controls
27 lines (22 loc) · 749 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
// KFH-Close/Closeable.java
public class Closeable implements AutoCloseable {
Object resource;
Closeable(Object resource) {
this.resource = resource;
// acquire resource, whatever it means...
System.out.println("Resource acquired");
}
@Override
public void close() throws Exception {
System.out.println("Closing " + resource);
if (((String)resource).startsWith("X"))
throw new RuntimeException(
"Exception from close");
}
public void doSomething(int n) {
System.out.println("In 'doSomething': "+resource);
if (n > 5)
throw new UnsupportedOperationException(
"Exception in doSomething");
}
}