Advertisement
Guest User

Untitled

a guest
Feb 29th, 2012
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. public class Unchecked<T extends Exception> {
  2.  
  3.     @SuppressWarnings("unchecked")
  4.     public static void uncheckedThrow(Exception exception) {
  5.         Unchecked<RuntimeException> asUnchecked = new Unchecked<RuntimeException>();
  6.         Unchecked raw = asUnchecked;
  7.         raw.t = exception;
  8.         asUnchecked.throwIt();
  9.     }  
  10.        
  11.     private T t;
  12.        
  13.     public void throwIt() throws T {
  14.         throw t;
  15.     }  
  16.  
  17.     public static void main(String[] args) {
  18.         Exception checked = new Exception();
  19.         uncheckedThrow(checked);
  20.     }  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement