Bohtvaroh

Blogger - JTCEWSD - 1

Nov 21st, 2012
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.53 KB | None | 0 0
  1. public class Util {
  2.     public static void main(String[] args) {
  3.         try {
  4.             throw new Throwable("msg");
  5.         } catch (Throwable t) {
  6.             throw sneakyThrow(t);
  7.         }
  8.     }
  9.  
  10.     static public RuntimeException sneakyThrow(Throwable t) {
  11.         if (t == null)
  12.             throw new NullPointerException();
  13.         Util.<RuntimeException>sneakyThrow0(t);
  14.         return null;
  15.     }
  16.  
  17.     static private <T extends Throwable> void sneakyThrow0(Throwable t) throws T {
  18.         throw (T) t;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment