java - Wrap exceptions by runtime exceptions with an annotation -


Is there a way to interpret a method so that all the exceptions dropped automatically to runtime exceptions?

  @ Magic annotation throws no segment! Void foo () {new exception ("bar") '}  

No way To do this, at least now I use an alternative solution like this (simplified):

  @SuppressWarnings ({"rawtypes", "uncheck"}) Public classes unchecked {Public Static Interface Uncheck Definition {InputStream openStream (); String readline (); ...} Private Static Class Proxy Class = Proxy .getProxyClass (Unchecked.clash.get classloader (), UncheckDefinition.class); Public Static UncheckedDefinitions Unchecked (Final Object Goal) {try {Return (UncheckedDefinitions) proxyClass.getConstructor (InvocationHandler.class) .newInstance (New InvocationHandler) {@Override throws public object invocation (object proxy, method method, object [] args) Throne (if the target of the class example) {return MethodUtils.invokeExactStaticMethod (class) target, method.getName (), args)}} return MethodUtils.invokeExactMethod (target, method.getName (), args);}}); } Hold (exception e) {new runtime exception (e); }}}  

And the usage looks like this:

  Import static .... Uncheck. *; ... author w = ...; Uncheck (W). Written (str, off, lane); The move is that the interface is "never ending" and all the time I need unchecked method, I will wrap that object in uncheck and generate the method signature in the IDE interface. 

Implementation is normal (reflective and "slow" but generally quite fast)

After some codes are processors and bytecodes-weavers, but it is possible (even so Aop or other JVM-based language) for my current project, so it was "invention".


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -