Skip to content

Commit a8e9077

Browse files
committed
multiple error handlers documentation to Handle/Catch
1 parent d808c9b commit a8e9077

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

err2.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ var (
7474
// return err
7575
// })
7676
//
77+
// You can have unlimited amount of error handlers. They are called if error
78+
// happens and they are called in the same order as they are given or until one
79+
// of them resets the error like Reset (notice other predefined error handlers)
80+
// in next sample:
81+
//
82+
// defer err2.Handle(err2.Noop, err2.Reset, err2.Log) // err2.Log not called!
83+
//
7784
// If you need to stop general panics in handler, you can do that by giving a
7885
// panic handler function:
7986
//
@@ -131,16 +138,23 @@ func Handle(err *error, a ...any) {
131138
// error handling function, i.e., err2.Handler. By returning nil resets the
132139
// error, which allows e.g. prevent automatic error logs to happening.
133140
// Otherwise, the output results depends on the current Tracer and assert
134-
// settings. Default setting print call stacks for panics but not for errors:
141+
// settings. The default trace setting prints call stacks for panics but not for
142+
// errors:
135143
//
136144
// defer err2.Catch(func(err error) error { return err} )
137145
//
138146
// or if you you prefer to use dedicated helpers:
139147
//
140148
// defer err2.Catch(err2.Noop)
141149
//
142-
// The last one calls your error handler, and you have an explicit panic
143-
// handler too, where you can e.g. continue panicking to propagate it for above
150+
// You can have unlimited amount of error handlers. They are called if error
151+
// happens and they are called in the same order as they are given or until one
152+
// of them resets the error like Reset in next sample:
153+
//
154+
// defer err2.Catch(err2.Noop, err2.Reset, err2.Log) // err2.Log not called!
155+
//
156+
// The last one calls your error handler, and you have an explicit panic handler
157+
// as well, where you can e.g. continue panicking to propagate it for above
144158
// callers or stop it like below:
145159
//
146160
// defer err2.Catch(func(err error) error { return err }, func(p any) {})

0 commit comments

Comments
 (0)