MCPcopy Index your code
hub / github.com/sourcegraph/conc / ExampleCatcher_error

Function ExampleCatcher_error

panics/panics_test.go:64–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62}
63
64func ExampleCatcher_error() {
65 helper := func() error {
66 var pc Catcher
67 pc.Try(func() { panic(errors.New("error")) })
68 return pc.Recovered().AsError()
69 }
70
71 if err := helper(); err != nil {
72 // In normal use cases, you can use err.Error() output directly to
73 // dump the panic's stack. This is not used in the example because
74 // its output is machine-specific - instead, we demonstrate getting
75 // the underlying error that was used for the panic.
76 if cause := errors.Unwrap(err); cause != nil {
77 fmt.Printf("helper panicked with an error: %s", cause)
78 }
79 }
80 // Output:
81 // helper panicked with an error: error
82}
83
84func TestCatcher(t *testing.T) {
85 t.Parallel()

Callers

nothing calls this directly

Calls 4

TryMethod · 0.95
RecoveredMethod · 0.95
AsErrorMethod · 0.80
UnwrapMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…