Created
April 16, 2021 20:13
-
-
Save rdp/cff5a69c7e403c92231acfc973a5fc03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestWasClosed { | |
public B() throws IOException { | |
//throw new IOException("and me?"); | |
} | |
@Override | |
public void close() throws Exception { | |
throw new IOException("nope"); | |
} | |
} | |
/** | |
* main: writes tapes after tape (until EXIT_AFTER_NEXT_FULL_TAPE_FILENAME comes into existence) | |
*/ | |
public static void main(String[] args) throws Throwable { | |
try (B b = new B()) { | |
int bb = 3; | |
int c = 3; | |
//throw new IOException("what abouot me?"); | |
}catch (IOException moi) { | |
int currentLine = new Throwable().getStackTrace()[0].getLineNumber(); | |
String currentFilename = new Throwable().getStackTrace()[0].getFileName(); | |
boolean exceptionWasDuringClose = Stream.of(moi.getStackTrace()).anyMatch(l -> l.getFileName().equals(currentFilename) && l.getLineNumber() == currentLine - 1); | |
if (exceptionWasDuringClose) { | |
int f = 3; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice work