Considering I'm using the original "errors" go package.
And, the difference between panic(11) and panic("11")?
Considering I'm using the original "errors" go package.
And, the difference between panic(11) and panic("11")?
panic
is defined as func panic(v interface{})
, calling panic(anything)
will print the the string representation of anything
then the stacktrace of the calling function.
Only difference is, if you use recover
, you will be able to access whatever you passed to panic, for example:
func main() {
defer func() {
if err := recover(); err != nil {
if n, ok := err.(int); ok && n == 11 {
fmt.Println("got 11!")
}
}
}()
panic(11)
}