Skip to content

Commit

Permalink
refactor(gnolang): move Exception to frame.go (#3596)
Browse files Browse the repository at this point in the history
minor refactor, just to put it in a place which I think is more
appropriate rather than being at the very top of the machine.go file.
  • Loading branch information
thehowl authored Feb 10, 2025
1 parent d2c3838 commit 00ff397
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
27 changes: 27 additions & 0 deletions gnovm/pkg/gnolang/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,30 @@ func toConstExpTrace(cte *ConstExpr) string {

return tv.T.String()
}

//----------------------------------------
// Exception

// Exception represents a panic that originates from a gno program.
type Exception struct {
// Value is the value passed to panic.
Value TypedValue
// Frame is used to reference the frame a panic occurred in so that recover() knows if the
// currently executing deferred function is able to recover from the panic.
Frame *Frame

Stacktrace Stacktrace
}

func (e Exception) Sprint(m *Machine) string {
return e.Value.Sprint(m)
}

// UnhandledPanicError represents an error thrown when a panic is not handled in the realm.
type UnhandledPanicError struct {
Descriptor string // Description of the unhandled panic.
}

func (e UnhandledPanicError) Error() string {
return e.Descriptor
}
24 changes: 0 additions & 24 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,6 @@ import (
"github.com/gnolang/gno/tm2/pkg/store"
)

// Exception represents a panic that originates from a gno program.
type Exception struct {
// Value is the value passed to panic.
Value TypedValue
// Frame is used to reference the frame a panic occurred in so that recover() knows if the
// currently executing deferred function is able to recover from the panic.
Frame *Frame

Stacktrace Stacktrace
}

func (e Exception) Sprint(m *Machine) string {
return e.Value.Sprint(m)
}

// UnhandledPanicError represents an error thrown when a panic is not handled in the realm.
type UnhandledPanicError struct {
Descriptor string // Description of the unhandled panic.
}

func (e UnhandledPanicError) Error() string {
return e.Descriptor
}

//----------------------------------------
// Machine

Expand Down

0 comments on commit 00ff397

Please sign in to comment.