Skip to content

Commit 00ff397

Browse files
authored
refactor(gnolang): move Exception to frame.go (#3596)
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.
1 parent d2c3838 commit 00ff397

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

gnovm/pkg/gnolang/frame.go

+27
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,30 @@ func toConstExpTrace(cte *ConstExpr) string {
216216

217217
return tv.T.String()
218218
}
219+
220+
//----------------------------------------
221+
// Exception
222+
223+
// Exception represents a panic that originates from a gno program.
224+
type Exception struct {
225+
// Value is the value passed to panic.
226+
Value TypedValue
227+
// Frame is used to reference the frame a panic occurred in so that recover() knows if the
228+
// currently executing deferred function is able to recover from the panic.
229+
Frame *Frame
230+
231+
Stacktrace Stacktrace
232+
}
233+
234+
func (e Exception) Sprint(m *Machine) string {
235+
return e.Value.Sprint(m)
236+
}
237+
238+
// UnhandledPanicError represents an error thrown when a panic is not handled in the realm.
239+
type UnhandledPanicError struct {
240+
Descriptor string // Description of the unhandled panic.
241+
}
242+
243+
func (e UnhandledPanicError) Error() string {
244+
return e.Descriptor
245+
}

gnovm/pkg/gnolang/machine.go

-24
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,6 @@ import (
1616
"github.com/gnolang/gno/tm2/pkg/store"
1717
)
1818

19-
// Exception represents a panic that originates from a gno program.
20-
type Exception struct {
21-
// Value is the value passed to panic.
22-
Value TypedValue
23-
// Frame is used to reference the frame a panic occurred in so that recover() knows if the
24-
// currently executing deferred function is able to recover from the panic.
25-
Frame *Frame
26-
27-
Stacktrace Stacktrace
28-
}
29-
30-
func (e Exception) Sprint(m *Machine) string {
31-
return e.Value.Sprint(m)
32-
}
33-
34-
// UnhandledPanicError represents an error thrown when a panic is not handled in the realm.
35-
type UnhandledPanicError struct {
36-
Descriptor string // Description of the unhandled panic.
37-
}
38-
39-
func (e UnhandledPanicError) Error() string {
40-
return e.Descriptor
41-
}
42-
4319
//----------------------------------------
4420
// Machine
4521

0 commit comments

Comments
 (0)