Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public <T extends EventArgs> T getUsableCopy()
- {
- // Here we go. A one line method with 18 lines of exception handling.
- // Somewhere, a kitten is dead. God's an evil bastard.
- try
- { return (T)this.<T>getClass().getConstructor(this.<T>getClass()).newInstance(this); }
- catch(IllegalAccessException e)
- { throw new RuntimeException("getCopy run on class: " + this.getClass().getSimpleName() + " did not have permission to create a new instance. This is one of the signs of the Apocalypse.", e); }
- catch(InvocationTargetException e)
- {
- Throwable cause = e.getCause();
- if(cause instanceof RuntimeException)
- throw (RuntimeException)cause;
- else if(cause instanceof Error)
- throw (Error)cause;
- else
- throw new RuntimeInvocationTargetException("", e.getCause());
- }
- catch(NoSuchMethodException e)
- { throw new RuntimeException("Class: " + this.getClass().getSimpleName() + " doesn't implement a constructor using its own type as a constructor. All descendents of EventArgs should.", e); }
- catch(InstantiationException e)
- { throw new RuntimeException("Unable to instantiate class:" + this.getClass().getSimpleName(), e); }
- }
Advertisement
Add Comment
Please, Sign In to add comment