github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/vm/exception.go (about) 1 package vm 2 3 import ( 4 "errors" 5 "math/big" 6 7 "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" 8 ) 9 10 // exceptionHandlingState represents state of the exception handling process. 11 type exceptionHandlingState byte 12 13 const ( 14 eTry exceptionHandlingState = iota 15 eCatch 16 eFinally 17 ) 18 19 // exceptionHandlingContext represents context of the exception handling process. 20 type exceptionHandlingContext struct { 21 CatchOffset int 22 FinallyOffset int 23 EndOffset int 24 State exceptionHandlingState 25 } 26 27 func newExceptionHandlingContext(cOffset, fOffset int) *exceptionHandlingContext { 28 return &exceptionHandlingContext{ 29 CatchOffset: cOffset, 30 FinallyOffset: fOffset, 31 EndOffset: -1, 32 State: eTry, 33 } 34 } 35 36 // HasCatch returns true iff the context has a `catch` block. 37 func (c *exceptionHandlingContext) HasCatch() bool { return c.CatchOffset >= 0 } 38 39 // HasFinally returns true iff the context has a `finally` block. 40 func (c *exceptionHandlingContext) HasFinally() bool { return c.FinallyOffset >= 0 } 41 42 // String implements the stackitem.Item interface. 43 func (c *exceptionHandlingContext) String() string { 44 return "exception handling context" 45 } 46 47 // Value implements the stackitem.Item interface. 48 func (c *exceptionHandlingContext) Value() any { 49 return c 50 } 51 52 // Dup implements the stackitem.Item interface. 53 func (c *exceptionHandlingContext) Dup() stackitem.Item { 54 return c 55 } 56 57 // TryBool implements the stackitem.Item interface. 58 func (c *exceptionHandlingContext) TryBool() (bool, error) { 59 panic("can't convert exceptionHandlingContext to Bool") 60 } 61 62 // TryBytes implements the stackitem.Item interface. 63 func (c *exceptionHandlingContext) TryBytes() ([]byte, error) { 64 return nil, errors.New("can't convert exceptionHandlingContext to ByteArray") 65 } 66 67 // TryInteger implements the stackitem.Item interface. 68 func (c *exceptionHandlingContext) TryInteger() (*big.Int, error) { 69 return nil, errors.New("can't convert exceptionHandlingContext to Integer") 70 } 71 72 // Type implements the stackitem.Item interface. 73 func (c *exceptionHandlingContext) Type() stackitem.Type { 74 panic("exceptionHandlingContext cannot appear on evaluation stack") 75 } 76 77 // Convert implements the stackitem.Item interface. 78 func (c *exceptionHandlingContext) Convert(_ stackitem.Type) (stackitem.Item, error) { 79 panic("exceptionHandlingContext cannot be converted to anything") 80 } 81 82 // Equals implements the stackitem.Item interface. 83 func (c *exceptionHandlingContext) Equals(s stackitem.Item) bool { 84 return c == s 85 }