Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-dambovaliev committed Nov 9, 2024
1 parent c3ec819 commit 6b6ab58
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gnovm/tests/files/recover12.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main


func main() {
defer func() {
r := recover()
println("recover:", r)
}()

arr := []int{1, 2, 3}
_ = arr[3] // Panics because index 3 is out of bounds
}

// Output:
// recover: slice index out of bounds: 3 (len=3)
15 changes: 15 additions & 0 deletions gnovm/tests/files/recover13.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main


func main() {
defer func() {
r := recover()
println("recover:", r)
}()

arr := []int{1, 2, 3}
_ = arr[-1:] // Panics because of negative index
}

// Output:
// recover: invalid slice index -1 (index must be non-negative)
15 changes: 15 additions & 0 deletions gnovm/tests/files/recover14.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main


func main() {
defer func() {
r := recover()
println("recover:", r)
}()

x, y := 10, 0
_ = x / y // Panics because of division by zero
}

// Output:
// recover: division by zero
15 changes: 15 additions & 0 deletions gnovm/tests/files/recover15.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main


func main() {
defer func() {
r := recover()
println("recover:", r)
}()

var i interface{} = "hello"
_ = i.(int) // Panics because i holds a string, not an int
}

// Output:
// recover: string is not of type int
14 changes: 14 additions & 0 deletions gnovm/tests/files/recover16.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main


func main() {
defer func() {
r := recover()
println("recover:", r)
}()

_ = make([]int, -1) // Panics because of negative length
}

// Output:
// recover: len out of range
15 changes: 15 additions & 0 deletions gnovm/tests/files/recover17.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main


func main() {
defer func() {
r := recover()
println("recover:", r)
}()

str := "hello"
_ = str[10] // Panics because index 10 is out of bounds
}

// Output:
// recover: index out of range [10] with length 5
15 changes: 15 additions & 0 deletions gnovm/tests/files/recover18.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main


func main() {
defer func() {
r := recover()
println("recover:", r)
}()

var m map[string]int // nil map
m["key"] = 42 // Panics when trying to assign to a nil map
}

// Output:
// recover: uninitialized map index
15 changes: 15 additions & 0 deletions gnovm/tests/files/recover19.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main


func main() {
defer func() {
r := recover()
println("recover:", r)
}()

var p *int
println(*p)
}

// Output:
// recover: nil pointer dereference

0 comments on commit 6b6ab58

Please sign in to comment.