Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureError ¶
CaptureError runs f and optionally adds the returned error to the given error. This is supposed to be used for handling errors in defer statements. The first argument should point to an error return parameter. Often, errors are discarded like this, which is error-prone as closing an open file might be necessary to flush the written contents:
var f *os.File // ... defer f.Close()
Instead, use CaptureError to handle the returned error:
func foo() (err error) { var f *os.File // ... defer runutil.CaptureError(&err, f.Close) // ... }
If the error return parameter is non-nil and Close errors, CaptureError sets the error return parameter to a multierror capturing both errors. If only one error occurs, the return parameter is set to exactly that error.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.