private void defineUncaughtExceptionHandler ( ) { MethodInfo mi = mClassFile . addMethod ( Modifiers . PRIVATE . toStatic ( true ) , UNCAUGHT_METHOD_NAME , null , new TypeDesc [ ] { TypeDesc . forClass ( Throwable . class ) } ) ; CodeBuilder b = new CodeBuilder ( mi ) ; // Thread t = Thread.currentThread(); // t.getUncaughtExceptionHandler().uncaughtException(t, e); TypeDesc threadType = TypeDesc . forClass ( Thread . class ) ; b . invokeStatic ( Thread . class . getName ( ) , "currentThread" , threadType , null ) ; LocalVariable threadVar = b . createLocalVariable ( null , threadType ) ; b . storeLocal ( threadVar ) ; b . loadLocal ( threadVar ) ; TypeDesc handlerType = TypeDesc . forClass ( Thread . UncaughtExceptionHandler . class ) ; b . invokeVirtual ( threadType , "getUncaughtExceptionHandler" , handlerType , null ) ; b . loadLocal ( threadVar ) ; b . loadLocal ( b . getParameter ( 0 ) ) ; b . invokeInterface ( handlerType , "uncaughtException" , null , new TypeDesc [ ] { threadType , TypeDesc . forClass ( Throwable . class ) } ) ; b . returnVoid ( ) ; }
Generates method which passes exception to uncaught exception handler .