Re: [go-nuts] Panic not recovered inside my panic recover function

2019-07-18 Thread T L
see https://go101.org/article/panic-and-recover-more.html for detailed explanations. On Thursday, July 18, 2019 at 12:52:13 PM UTC+8, ZPL wrote: > > Sorry for the bad formatting. > > > recover must be called directly by a deferred function > func logPanic() { > defer func() { > if err :=

Re: [go-nuts] Panic not recovered inside my panic recover function

2019-07-17 Thread Dan Kortschak
You could try it this way if you really need a separate function. https://play.golang.org/p/V-ysjWbZ2X5 On Thu, 2019-07-18 at 12:51 +0800, ZP L wrote: > Sorry for the bad formatting. > > > recover must be called directly by a deferred function > > func logPanic() { > defer func() { > if

Re: [go-nuts] Panic not recovered inside my panic recover function

2019-07-17 Thread Dan Kortschak
The defer is not being run directly as a result of the panic. >From the spec: > The recover function allows a program to manage behavior of a > panicking goroutine. Suppose a function G defers a function D that > calls recover and a panic occurs in a function on the same goroutine > in which G

Re: [go-nuts] Panic not recovered inside my panic recover function

2019-07-17 Thread Ian Lance Taylor
On Wed, Jul 17, 2019 at 9:51 PM ZP L wrote: > > Sorry for the bad formatting. > > > recover must be called directly by a deferred function > func logPanic() { > defer func() { > if err := recover(); err != nil { >fmt.Println("got panic") >return > } > }() > } >

Re: [go-nuts] Panic not recovered inside my panic recover function

2019-07-17 Thread ZP L
Sorry for the bad formatting. > recover must be called directly by a deferred function func logPanic() { defer func() { if err := recover(); err != nil { fmt.Println("got panic") return } }() } This still not working. >From

Re: [go-nuts] Panic not recovered inside my panic recover function

2019-07-17 Thread Ian Lance Taylor
On Wed, Jul 17, 2019 at 5:11 AM Tamás Gulácsi wrote: > > The "recover()" call must be in the deferred part. Yes, as the spec says, recover must be called directly by a deferred function. When sending code to this list, please use a link to the Go playground or use plain text. The highlighted