Skip to content

Commit

Permalink
fixed Source path must actually exist in AboutTryWithResources matyb#49
Browse files Browse the repository at this point in the history
  • Loading branch information
darsen committed Mar 19, 2015
1 parent 15bd879 commit a2f30f0
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions koans/src/java7/AboutTryWithResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@

public class AboutTryWithResources {

class AutoClosableResource implements AutoCloseable{
public void foo() throws WorkException{
throw new WorkException("Exception thrown while working");
}
public void close() throws CloseException{
throw new CloseException("Exception thrown while closing");
}
}

class WorkException extends Exception {
public WorkException(String message) {
super(message);
}
}

class CloseException extends Exception {
public CloseException(String message) {
super(message);
}
}

@Koan
public void lookMaNoClose() {
String str = "first line"
Expand All @@ -30,11 +51,13 @@ public void lookMaNoClose() {

@Koan
public void lookMaNoCloseWithException() throws IOException {
String line;
String line = "no need to close readers";
try (BufferedReader br =
new BufferedReader(
new FileReader("I do not exist!"))) {
line = br.readLine();
}catch(FileNotFoundException e){
line = "no more leaking!";
}
assertEquals(line, __);
}
Expand Down Expand Up @@ -82,25 +105,4 @@ public void bar() throws CloseException, WorkException {
autoClosableResource.foo();
}
}
}

class AutoClosableResource implements AutoCloseable{
public void foo() throws WorkException{
throw new WorkException("Exception thrown while working");
}
public void close() throws CloseException{
throw new CloseException("Exception thrown while closing");
}
}

class WorkException extends Exception {
public WorkException(String message) {
super(message);
}
}

class CloseException extends Exception {
public CloseException(String message) {
super(message);
}
}
}

0 comments on commit a2f30f0

Please sign in to comment.