2004-11-10 | Paul Boddie | raw annotate files changeset graph | Reverted the ret instruction's implementation to use return addresses. Introduced finally handler detection to produce END_FINALLY rather than RAISE_VARARGS from athrow instructions. Fixed invokevirtual. Changed new and invokespecial to work better with the Python initialisation model, removing the __java_init__ method. Now, the new instruction yields a class reference which is then used accordingly by invokespecial. However, invokespecial is made aware of whether it is operating within an <init> method, although this may need further examination. Changed the translate, disassemble and BytecodeReader.process signatures to work on methods rather than separate code and exception table objects. |
1 public class ExceptionTest { 2 3 public int testThrow(int x) throws java.lang.Exception { 4 if (x == 0) { 5 throw new MyException(); 6 } else if (x == 1) { 7 throw new MyOtherException(); 8 } else { 9 return 1; 10 } 11 } 12 13 public int testCatch(int x) { 14 try { 15 if (x == 0) { 16 throw new MyException(); 17 } else if (x == 1) { 18 throw new MyOtherException(); 19 } else { 20 x = 1; 21 } 22 } catch (MyException exc) { 23 x = 3; 24 } catch (MyOtherException exc) { 25 x = 2; 26 } 27 return x; 28 } 29 30 public int testIncomingCatch(int x) { 31 try { 32 return testThrow(x); 33 } catch (MyException exc) { 34 return 3; 35 } catch (MyOtherException exc) { 36 return 2; 37 } catch (java.lang.Exception exc) { 38 return -1; // Should be unreachable, really. 39 } 40 } 41 42 public int testFinally(int x) throws java.lang.Exception { 43 try { 44 if (x == 0) { 45 x = 3; 46 throw new MyException(); 47 } else if (x == 1) { 48 x = 2; 49 throw new MyOtherException(); 50 } 51 } finally { 52 x = 1; 53 } 54 return x; 55 } 56 57 public int testCatchFinally(int x) { 58 try { 59 if (x == 0) { 60 throw new MyException(); 61 } else if (x == 1) { 62 throw new MyOtherException(); 63 } 64 } catch (MyException exc) { 65 x = 3; 66 } catch (MyOtherException exc) { 67 x = 2; 68 } finally { 69 x = 1; 70 } 71 return x; 72 } 73 } 74 75 class MyException extends java.lang.Exception { 76 } 77 78 class MyOtherException extends java.lang.Exception { 79 } 80 81 // vim: tabstop=4 expandtab shiftwidth=4