Skip to content

Instantly share code, notes, and snippets.

@rdp
Created April 16, 2021 20:13
Show Gist options
  • Save rdp/cff5a69c7e403c92231acfc973a5fc03 to your computer and use it in GitHub Desktop.
Save rdp/cff5a69c7e403c92231acfc973a5fc03 to your computer and use it in GitHub Desktop.
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;
}
}
}
}
@alexb105
Copy link

nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment