Defer/go statement calls 'recover' or 'panic' directly
Reports defer
and go
statements that call panic()
or recover()
directly.
Such statements are rarely useful and might indicate a misuse of the panic()
and recover()
mechanism. In particular:
go panic()
: a newly-started goroutine will panic immediately.defer panic()
: a function with this statement will always panic on exit.go recover()
: has no effect as newly-started goroutine cannot panic.defer recover()
: function with this statement will silently stop panicking. This could be a valid usage, but an idiomatic way is to inspect the value returned byrecover()
:defer func() { if r := recover(); r != nil { fmt.Println("Recovered from: ", r) } }()
For more information about go statements and panics handling, refer to Handling panics and Go statements in the Go Language Specification.
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
GoDeferGo- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Go, 243.23131 |