Skip to content

Instantly share code, notes, and snippets.

@wader
Created May 26, 2021 14:24
Show Gist options
  • Save wader/a3de44912c85e1ab37add5f7fda58791 to your computer and use it in GitHub Desktop.
Save wader/a3de44912c85e1ab37add5f7fda58791 to your computer and use it in GitHub Desktop.
go recover runtime error test
package main
import (
"fmt"
"runtime"
)
func a(f func()) {
defer func() {
if rv := recover(); rv != nil {
fmt.Println("recovered", rv)
if _, ok := rv.(runtime.Error); ok {
fmt.Println("runtime error")
}
}
}()
f()
}
func main() {
fmt.Println("Hello, playground")
a(func() {
var a []int
a[123] = 1
})
a(func() {
panic("asdasd")
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment