Documentation
¶
Overview ¶
Package errorhelper contains error-related helpers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallerError ¶
CallerError prepends the provided error with caller function/method name and the provided parameters. If there are no parameters, colon is used. If 'err' is nil, nil is returned.
Example ¶
errf1 := CallerError(error1)
fmt.Println(errf1.Error())
errf2 := CallerError(error1, " ")
fmt.Println(errf2.Error())
ermth := errMethod{}
errm1 := ermth.Error1()
fmt.Println(errm1.Error())
errm2 := ermth.Error2()
fmt.Println(errm2.Error())
Output: ExampleCallerError:error1 ExampleCallerError error1 errMethod.Error1: error1 (*errMethod).Error2--error1
func PanicToError ¶
PanicToError converts panic to error in the following way:
- if surrounding function panics with an error, this error is returned;
- if surrounding function panics with a string, the error wrapping this string is returned;
- if surrounding function panics with a fmt.Stringer, the error wrapping fmt.Stringer.String is returned;
- if surrounding function panics with an encoding.TextMarshaler, the error wrapping encoding.TextMarshaler.MarshalText is returned;
- otherwise the panic is reraised.
PanicToError must be called from a defer statement:
func Example() (err error) {
defer func() {
PanicToError(recover(), &err)
}()
return nil
}
(See tests.)
Types ¶
This section is empty.
Source Files
¶
- doc.go
- errorhelper.go
- panictoerror.go
Click to show internal directories.
Click to hide internal directories.