Calling panic with a nil panic value is allowed in Go 1, but weird.
Almost all code checks for panics with:
defer func() {
if e := recover(); e != nil { ... }
}()
... which is not correct in the case of panic(nil).
The proper way is more like:
panicked := true
defer func() {
if panicked {
e := recover()
...
}
}()
...
panicked = false
return
....
panicked = false
return
Proposal: make the runtime panic function promote its panic value from nil to something like a runtime.NilPanic global value of private, unassignable type:
package runtime
type nilPanic struct{}
// NilPanic is the value returned by recover when code panics with a nil value.
var NilPanic nilPanic
Probably Go2.
Calling
panicwith anilpanic value is allowed in Go 1, but weird.Almost all code checks for panics with:
... which is not correct in the case of
panic(nil).The proper way is more like:
Proposal: make the runtime
panicfunction promote its panic value fromnilto something like aruntime.NilPanicglobal value of private, unassignable type:Probably Go2.