Exception Handling
TRY / CATCH / FINALLY Opcodes
NeoVM supports structured exception handling:
TRYbegins a try block, specifying catch and/or finally offsetsTHROWraises an exception (top of stack becomes the exception object)ENDTRYexits the try block normally, jumping to the end offsetENDFINALLYexits the finally block; if an exception is pending, it is rethrown
Exception Propagation
- When
THROWis executed, the VM searches the current context's exception handler stack - If a catch handler is found, execution jumps to the catch offset with the exception on the stack
- If a finally handler exists, it executes before propagation continues
- If no handler is found in the current context, the exception propagates to the caller
ENDFINALLYrethrows any pending exception that was not handled by the catch block
Gas Effects
Gas continues to be consumed during exception handling. The TRY, ENDTRY, and ENDFINALLY opcodes each cost 1 gas unit. Stack unwinding during propagation does not have additional gas cost beyond the opcodes executed.
