Handling panic in go


(Arunhfb) #1

panic: TypeInfo already exists for exported.Account

goroutine 1 [running]:

/home/arun/go/src/github.com/blockkungpao/fbc/app.go:313 +0x115

main.main()
/home/arun/go/src/github.com/blockkungpao/fbc/cmd/fbd/main.go:79 +0x2d
strong text
how to handle these unexpected behaviour?


(Norbert Melzer) #2

The best way were to not let it happen at all.

Write your code in a way that panics don’t occur…

Though you can use defer and recover to “catch” a panic. Wont give you much when you do it in main though, as it will exit anyway (at the point when the defered function is called, then main is already left…

You can not just restart your program or continue after the try/catch block as you would in many other languages.


(Arunhfb) #3

how can I know what is the error(in which file it is) and how to remove it.


(Norbert Melzer) #4

Learn how to read the trace.

From what you have posted, I’d take a look at line 313 of github.com/blockkungpao/fbc/app.go. Its not available (publicly) on GitHub though…