Skip to content

Commit

Permalink
multiple error handlers documentation to Handle/Catch
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Feb 18, 2024
1 parent d808c9b commit a8e9077
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions err2.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ var (
// return err
// })
//
// You can have unlimited amount of error handlers. They are called if error
// happens and they are called in the same order as they are given or until one
// of them resets the error like Reset (notice other predefined error handlers)
// in next sample:
//
// defer err2.Handle(err2.Noop, err2.Reset, err2.Log) // err2.Log not called!
//
// If you need to stop general panics in handler, you can do that by giving a
// panic handler function:
//
Expand Down Expand Up @@ -131,16 +138,23 @@ func Handle(err *error, a ...any) {
// error handling function, i.e., err2.Handler. By returning nil resets the
// error, which allows e.g. prevent automatic error logs to happening.
// Otherwise, the output results depends on the current Tracer and assert
// settings. Default setting print call stacks for panics but not for errors:
// settings. The default trace setting prints call stacks for panics but not for
// errors:
//
// defer err2.Catch(func(err error) error { return err} )
//
// or if you you prefer to use dedicated helpers:
//
// defer err2.Catch(err2.Noop)
//
// The last one calls your error handler, and you have an explicit panic
// handler too, where you can e.g. continue panicking to propagate it for above
// You can have unlimited amount of error handlers. They are called if error
// happens and they are called in the same order as they are given or until one
// of them resets the error like Reset in next sample:
//
// defer err2.Catch(err2.Noop, err2.Reset, err2.Log) // err2.Log not called!
//
// The last one calls your error handler, and you have an explicit panic handler
// as well, where you can e.g. continue panicking to propagate it for above
// callers or stop it like below:
//
// defer err2.Catch(func(err error) error { return err }, func(p any) {})
Expand Down

0 comments on commit a8e9077

Please sign in to comment.