@@ -655,9 +655,22 @@ func ExampleHandle_errThrow() {
655
655
// Output: testing: run example: our error
656
656
}
657
657
658
+ func ExampleHandle_annotatedErrReturn () {
659
+ normalReturn := func () (err error ) {
660
+ defer err2 .Handle (& err ) // automatic annotation
661
+ return fmt .Errorf ("our error" )
662
+ }
663
+ err := normalReturn ()
664
+ fmt .Printf ("%v" , err )
665
+
666
+ // ------- automatic in Go example/test
667
+ // ------- v ------------------ v --------
668
+ // Output: testing: run example: our error
669
+ }
670
+
658
671
func ExampleHandle_errReturn () {
659
672
normalReturn := func () (err error ) {
660
- defer err2 .Handle (& err , "" )
673
+ defer err2 .Handle (& err , nil ) // nil disables automatic annotation
661
674
return fmt .Errorf ("our error" )
662
675
}
663
676
err := normalReturn ()
@@ -729,7 +742,9 @@ func ExampleHandle_handlerFn() {
729
742
doSomething := func (a , b int ) (err error ) {
730
743
defer err2 .Handle (& err , func (err error ) error {
731
744
// Example for just annotating current err. Normally Handle is
732
- // used for cleanup. See CopyFile example for more information.
745
+ // used for e.g. cleanup, not annotation that can be left for
746
+ // err2 automatic annotation. See CopyFile example for more
747
+ // information.
733
748
return fmt .Errorf ("error with (%d, %d): %v" , a , b , err )
734
749
})
735
750
try .To1 (throw ())
@@ -740,6 +755,26 @@ func ExampleHandle_handlerFn() {
740
755
// Output: error with (1, 2): this is an ERROR
741
756
}
742
757
758
+ func ExampleHandle_multipleHandlerFns () {
759
+ doSomething := func (a , b int ) (err error ) {
760
+ defer err2 .Handle (& err ,
761
+ // cause automatic annotation <== 2 error handlers do the trick
762
+ err2 .Noop ,
763
+ func (err error ) error {
764
+ // Example for just annotating current err. Normally Handle
765
+ // is used for e.g. cleanup, not annotation that can be left
766
+ // for err2 automatic annotation. See CopyFile example for
767
+ // more information.
768
+ return fmt .Errorf ("%w error with (%d, %d)" , err , a , b )
769
+ })
770
+ try .To1 (throw ())
771
+ return err
772
+ }
773
+ err := doSomething (1 , 2 )
774
+ fmt .Printf ("%v" , err )
775
+ // Output: testing: run example: this is an ERROR error with (1, 2)
776
+ }
777
+
743
778
func ExampleHandle_noThrow () {
744
779
doSomething := func (a , b int ) (err error ) {
745
780
defer err2 .Handle (& err , func (err error ) error {
0 commit comments