crash.go
Crashes with
kirr@deco:~/tmp/trashme$ go run crash.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x484d04]
goroutine 1 [running]:
main.derefInt(...)
/home/kirr/tmp/trashme/crash.go:7
main.crash(...)
/home/kirr/tmp/trashme/crash.go:12
main.doSmth1(...)
/home/kirr/tmp/trashme/crash.go:16
main.doSmth2(...)
/home/kirr/tmp/trashme/crash.go:20
main.main()
/home/kirr/tmp/trashme/crash.go:34 +0x4
exit status 2
The fault is actually not crash - nil memory access generates an exception that can be handled: With
--- a/crash.go.kirr
+++ b/crash.go
@@ -22,7 +22,7 @@ func doSmth2() {
func main() {
- if false {
+ if true {
defer func() {
e := recover()
if e != nil {
it becomes
kirr@deco:~/tmp/trashme$ go run crash.go
recovered; error was: runtime error: invalid memory address or nil pointer dereference
Please register or sign in to comment