Documentation ¶
Overview ¶
Package builtinhelper contains helpers for [builtin] package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
Click to show internal directories.
Click to hide internal directories.