Skip to content

Commit b756914

Browse files
committed
more go doc to try.ToX functions
1 parent 56256a7 commit b756914

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

try/try.go

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,34 +67,58 @@ import (
6767
"github.com/lainio/err2"
6868
)
6969

70-
// To is a helper function to call functions which returns (error)
71-
// and check the error value. If an error occurs, it panics the error where err2
72-
// handlers can catch it if needed.
70+
// To is a helper function to call functions which returns an error value and
71+
// check the value. If an error occurs, it panics the error so that err2
72+
// handlers can catch it if needed. Note! If no err2.Handle or err2.Catch exist
73+
// in the call stack and To detects the error, the error is not handled, and the
74+
// app will crash. When using try.To functions you should always have proper
75+
// err2.Handle or err2.Catch statements in the call stack.
76+
//
77+
// defer err2.Handle(&err)
78+
// ...
79+
// try.To(w.Close())
7380
func To(err error) {
7481
if err != nil {
7582
panic(err)
7683
}
7784
}
7885

79-
// To1 is a helper function to call functions which returns (T, error)
80-
// and check the error value. If an error occurs, it panics the error where err2
81-
// handlers can catch it if needed.
86+
// To1 is a helper function to call functions which returns values (T, error)
87+
// and check the error value. If an error occurs, it panics the error so that
88+
// err2 handlers can catch it if needed. Note! If no err2.Handle or err2.Catch
89+
// exist in the call stack and To1 detects the error, the error is not handled,
90+
// and the app will crash. When using try.To1 functions you should always have
91+
// proper err2.Handle or err2.Catch statements in the call stack.
92+
//
93+
// defer err2.Handle(&err)
94+
// ...
95+
// r := try.To1(os.Open(src))
8296
func To1[T any](v T, err error) T {
8397
To(err)
8498
return v
8599
}
86100

87-
// To2 is a helper function to call functions which returns (T, U, error)
88-
// and check the error value. If an error occurs, it panics the error where err2
89-
// handlers can catch it if needed.
101+
// To2 is a helper function to call functions which returns values (T, U, error)
102+
// and check the error value. If an error occurs, it panics the error so that
103+
// err2 handlers can catch it if needed. Note! If no err2.Handle or err2.Catch
104+
// exist in the call stack and To2 detects the error, the error is not handled,
105+
// and the app will crash. When using try.To2 functions you should always have
106+
// proper err2.Handle or err2.Catch statements in the call stack.
107+
//
108+
// defer err2.Handle(&err)
109+
// ...
110+
// kid, pk := try.To2(keys.CreateAndExportPubKeyBytes(kms.ED25519))
90111
func To2[T, U any](v1 T, v2 U, err error) (T, U) {
91112
To(err)
92113
return v1, v2
93114
}
94115

95-
// To3 is a helper function to call functions which returns (T, U, V, error)
96-
// and check the error value. If an error occurs, it panics the error where err2
97-
// handlers can catch it if needed.
116+
// To3 is a helper function to call functions which returns values (T, U, V,
117+
// error) and check the error value. If an error occurs, it panics the error so
118+
// that err2 handlers can catch it if needed. Note! If no err2.Handle or
119+
// err2.Catch exist in the call stack and To3 detects the error, the error is
120+
// not handled, and the app will crash. When using try.To3 functions you should
121+
// always have proper err2.Handle or err2.Catch statements in the call stack.
98122
func To3[T, U, V any](v1 T, v2 U, v3 V, err error) (T, U, V) {
99123
To(err)
100124
return v1, v2, v3

0 commit comments

Comments
 (0)