theres also a throwException(Throwable) in sun.misc.Unsafe - though to
use that you really have to want to

On Wed, Aug 26, 2009 at 12:30 AM, Christian
Catchpole<[email protected]> wrote:
>
> Compile this..  (any package you like, or no package at all)
>
> public class Rethrow {
>    public static void unchecked(Throwable t) {
>        t=t;
>    }
> }
>
> javap reports the byte code as..
>
> public static void unchecked(java.lang.Throwable);
>  Code:
>   Stack=1, Locals=1, Args_size=1
>   0:   aload_0
>   1:   astore_0
>   2:   return
>
> which in hex is:
>
> 2A 4B B1
>
> open the class file in the hex editor, search for that and change it
> to:
>
> 2A BF B1
>
> javap now reports the byte code as..
>
> public static void unchecked(java.lang.Throwable);
>  Code:
>   Stack=1, Locals=1, Args_size=1
>   0:   aload_0
>   1:   athrow
>   2:   return
>
> jar that class up or otherwise protect it from re-write.
>
> In your code you can now call this without wrapping with a runtime
> exception.  And the stack trace is still that of the original
> exception.
>
> } catch(Exception e) {
>  Rethrow.unchecked(e);
> }
>
> Obviously, use at your own risk.  No warrenties etc. :)
>
> >
>



-- 
http://mapsdev.blogspot.com/
Marcelo Takeshi Fukushima

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to