It may or may not panic. General rule is to always check the returned error first, and if that is nil
, only then proceed to use other return values.
If you get a non-nil
error, other return values are "undefined", they may be nil
, and thus calling their methods may easily result in a runtime panic.
There may be exceptions of course which are usually documented, e.g. http.Get()
may return an error and a non-nil
response if following redirection fails, providing details about the error. But this is rare, and should always be documented. DB.Query()
does not document such deviation, so you can't rely on that.
See related: Do we need to close the response object if an error occurs while calling http.Get(url)?