@@ -67,34 +67,58 @@ import (
67
67
"github.com/lainio/err2"
68
68
)
69
69
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())
73
80
func To (err error ) {
74
81
if err != nil {
75
82
panic (err )
76
83
}
77
84
}
78
85
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))
82
96
func To1 [T any ](v T , err error ) T {
83
97
To (err )
84
98
return v
85
99
}
86
100
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))
90
111
func To2 [T , U any ](v1 T , v2 U , err error ) (T , U ) {
91
112
To (err )
92
113
return v1 , v2
93
114
}
94
115
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.
98
122
func To3 [T , U , V any ](v1 T , v2 U , v3 V , err error ) (T , U , V ) {
99
123
To (err )
100
124
return v1 , v2 , v3
0 commit comments