Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test2 {
- public static void testTryWithResAndBreak() {
- while (true) {
- try {
- System.out.println("we are in (while(true))");
- Resources resources = getResources();
- try {
- resources = getResources();
- System.out.println("We are in try block");
- if (true) {
- System.out.println("We are in the if(true) now! Next step is break");
- break;
- }
- System.out.println("OOOOO___OOOO WE ARE HERE!!!");
- resources.writeSomething();
- } catch (Exception e) {
- System.out.println("Catched exception");
- } finally {
- resources.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- private static class Resources implements AutoCloseable {
- @Override
- public void close() throws Exception {
- System.out.println("Resources closed");
- throw new Exception("Exception after closed resources!");
- }
- public void writeSomething() {
- System.out.println("i wrote something");
- }
- }
- private static Resources getResources() {
- return new Resources();
- }
- public static void main(String[] args) {
- testTryWithResAndBreak();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement