Exception handling instructions



      enter_try      jsr      ret_jsr      throw
      throw_caller   


 enter_try 
  ·  OperationEnter try context for the current method
  ·  Format
prefix
enter_try
  ·  Direct Format
{enter_try}
  ·  Forms enter_try = 255, 27 (0xFF, 0x1B)
   · Description The exception frame height for the current method is set to the current height of the stack.
   · Notes This must be in the prolog of any method that includes try blocks. It sets the "base height" of the stack so that throw instructions know where to unwind the stack to when an exception is thrown.


 jsr 
  ·  OperationJump to local subroutine
  ·  Format
jsr
offset
0
0
0
0
br_long
jsr
offset1
offset2
offset3
offset4
  ·  Direct Format
{jsr}
dest
  ·  Forms jsr = 218 (0xDA)
  ·  Stack... => ..., address
   · Description The program counter for the next instruction (pc + 6) is pushed on the stack as type ptr. Then the program branches to pc + offset.
   · Notes This instruction is used to implement finally blocks.


 ret_jsr 
  ·  OperationReturn from local subroutine
  ·  Format
ret_jsr
  ·  Direct Format
{ret_jsr}
  ·  Forms ret_jsr = 219 (0xDB)
  ·  Stack..., address => ...
   · Description The address is popped from the stack as the type ptr and transferred into pc.
   · Notes This instruction is used to implement finally blocks.


 throw 
  ·  OperationThrow an exception
  ·  Format
prefix
throw
  ·  Direct Format
{throw}
  ·  Forms throw = 255, 28 (0xFF, 0x1C)
  ·  Stack..., working1, ..., workingN, object => ..., object
   · Description The object is popped from the stack as type ptr. The stack is then reset to the same as the current method's exception frame height. Then, object is re-pushed onto the stack and control is passed to the current method's exception matching code.
   · Notes This is used to throw exceptions within methods that have an enter_try instruction. Use throw_caller if the method does not include try blocks.

Setting the stack height to the exception frame height ensures that all working values are removed from the stack prior to entering the exception matching code.



 throw_caller 
  ·  OperationThrow an exception to the caller of this method
  ·  Format
prefix
throw_caller
  ·  Direct Format
{throw_caller}
  ·  Forms throw_caller = 255, 29 (0xFF, 0x1D)
  ·  Stack..., working1, ..., workingN, object => ..., object
   · Description The object is popped from the stack as type ptr. The call frame stack is then unwound until a call frame with a non-zero exception frame height is found. The stack is then reset to the specified exception frame height. Then, object is re-pushed onto the stack and control is passed to the call frame method's exception matching code.
   · Notes This is used to throw exceptions from within methods that do not have an enter_try instruction. Use throw if the method does include try blocks.


Copyright © Southern Storm Software Pty Ltd 2002
Licensed under GNU FDL