Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. public class Test2 {
  2.     public static void testTryWithResAndBreak() {
  3.         while (true) {
  4.             try {
  5.                 System.out.println("we are in (while(true))");
  6.                 Resources resources = getResources();
  7.                 try {
  8.                     resources = getResources();
  9.                     System.out.println("We are in try block");
  10.                     if (true) {
  11.                         System.out.println("We are in the if(true) now! Next step is break");
  12.                         break;
  13.                     }
  14.                     System.out.println("OOOOO___OOOO WE ARE HERE!!!");
  15.                     resources.writeSomething();
  16.                 } catch (Exception e) {
  17.                     System.out.println("Catched exception");
  18.                 } finally {
  19.                     resources.close();
  20.                 }
  21.             } catch (Exception e) {
  22.                 e.printStackTrace();
  23.             }
  24.  
  25.         }
  26.     }
  27.     private static class Resources implements AutoCloseable {
  28.         @Override
  29.         public void close() throws Exception {
  30.             System.out.println("Resources closed");
  31.             throw new Exception("Exception after closed resources!");
  32.         }
  33.  
  34.         public void writeSomething() {
  35.             System.out.println("i wrote something");
  36.         }
  37.     }
  38.  
  39.     private static Resources getResources() {
  40.         return new Resources();
  41.     }
  42.  
  43.     public static void main(String[] args) {
  44.         testTryWithResAndBreak();
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement