2004-11-09 | Paul Boddie | file changeset files shortlog | Fixed comparison plus branch (if_acmp*) by removing the comparison result from the operand stack. Added stack top duplication before RAISE_VARARGS so that the appropriate handlers can save the value. Changed the value stored in the load_const_ret method so that None is stored (although this may need verifying). When the translated ret instruction (END_FINALLY in the Python VM, again requiring verification) is executed, the value loaded just prior to its execution should be the same as that saved at the beginning of the handler, and this should be None or a raised exception. NOTE: The load_const_ret translation should arguably retrieve the saved NOTE: value from the beginning of any active handler instead of just NOTE: loading None. This may be assured in try...finally constructs NOTE: (without catch sections), however. Rearranged Python VM instruction insertion for exceptions. Changed some load_global(None) usage to load_const(None). Added instruction positions in the disassembly output. |
paul@16 | 1 | public class ExceptionTest { |
paul@16 | 2 | |
paul@16 | 3 | public int testCatch() { |
paul@16 | 4 | try { |
paul@16 | 5 | throw new MyException(); |
paul@16 | 6 | } catch (MyException exc) { |
paul@16 | 7 | return 1; |
paul@16 | 8 | } |
paul@16 | 9 | } |
paul@16 | 10 | |
paul@16 | 11 | public int testFinally(int x) { |
paul@16 | 12 | try { |
paul@16 | 13 | if (x == 0) { |
paul@16 | 14 | throw new MyException(); |
paul@16 | 15 | } else if (x == 1) { |
paul@16 | 16 | throw new MyOtherException(); |
paul@16 | 17 | } |
paul@16 | 18 | } catch (MyException exc) { |
paul@16 | 19 | x = 3; |
paul@16 | 20 | } catch (MyOtherException exc) { |
paul@16 | 21 | x = 2; |
paul@16 | 22 | } finally { |
paul@16 | 23 | x = 1; |
paul@16 | 24 | } |
paul@16 | 25 | return x; |
paul@16 | 26 | } |
paul@16 | 27 | } |
paul@16 | 28 | |
paul@16 | 29 | class MyException extends java.lang.Exception { |
paul@16 | 30 | } |
paul@16 | 31 | |
paul@16 | 32 | class MyOtherException extends java.lang.Exception { |
paul@16 | 33 | } |
paul@16 | 34 | |
paul@16 | 35 | // vim: tabstop=4 expandtab shiftwidth=4 |