Skip to content

Commit 089db87

Browse files
committed
hyperlinks in docs
1 parent 8ab23ac commit 089db87

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

try/try.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Package try is a package for try.ToX functions that implement the error
3-
checking. try.ToX functions check 'if err != nil' and if it throws the err to the
2+
Package try is a package for [To], [To1], and [To2] functions that implement the error
3+
checking. [To] functions check 'if err != nil' and if it throws the err to the
44
error handlers, which are implemented by the err2 package. More information
55
about err2 and try packager roles can be seen in the FileCopy example:
66
@@ -20,31 +20,33 @@ about err2 and try packager roles can be seen in the FileCopy example:
2020
2121
# try.To — Fast Checking
2222
23-
All of the try.To functions are as fast as the simple 'if err != nil {'
23+
All of the [To] functions are as fast as the simple 'if err != nil {'
2424
statement, thanks to the compiler inlining and optimization.
2525
26-
Note that try.ToX function names end to a number (x) because:
26+
We have three error check functions: [To], [To1], and [To2] because:
2727
2828
"No variadic type parameters. There is no support for variadic type parameters,
2929
which would permit writing a single generic function that takes different
3030
numbers of both type parameters and regular parameters." - Go Generics
3131
32-
The leading number at the end of the To2 tells that To2 takes two different
33-
non-error arguments, and the third one must be an error value.
32+
For example, the leading number at the end of the [To2] tells that [To2] takes
33+
two different non-error arguments, and the third one must be an error value.
3434
35-
Looking at the FileCopy example again, you see that all the functions
36-
are directed to try.To1 are returning (type1, error) tuples. All of these
37-
tuples are the correct input to try.To1. However, if you have a function that
38-
returns (type1, type2, error), you must use try.To2 function to check the error.
39-
Currently the try.To3 takes (3 + 1) return values which is the greatest amount.
35+
Looking at the [CopyFile] example again, you see that all the functions
36+
are directed to [To1] are returning (type1, error) tuples. All of these
37+
tuples are the correct input to [To1]. However, if you have a function that
38+
returns (type1, type2, error), you must use [To2] function to check the error.
39+
Currently the [To3] takes (3 + 1) return values which is the greatest amount.
4040
If more is needed, let us know.
4141
4242
# try.Out — Error Handling Language
4343
44-
The try package offers an error handling DSL. It's for cases where you want to
45-
do something specific after error returing function call. For example, you might
46-
want to ignore the specific error and use a default value. That's possible with
47-
the following code:
44+
The try package offers an error handling DSL that's based on [Out], [Out1], and
45+
[Out2] functions and their corresponding return values [Result], [Result1], and
46+
[Result2]. DSL is for the cases where you want to do something specific after
47+
error returning function call. Those cases are rare. But you might want, for
48+
example, to ignore the specific error and use a default value without any
49+
special error handling. That's possible with the following code:
4850
4951
number := try.Out1(strconv.Atoi(str)).Catch(100)
5052
@@ -71,7 +73,7 @@ import (
7173
// check the value. If an error occurs, it panics the error so that err2
7274
// handlers can catch it if needed. Note! If no err2.Handle or err2.Catch exist
7375
// in the call stack and To panics an error, the error is not handled, and the
74-
// app will crash. When using try.To functions you should always have proper
76+
// app will crash. When using To function you should always have proper
7577
// err2.Handle or err2.Catch statements in the call stack.
7678
//
7779
// defer err2.Handle(&err)
@@ -87,7 +89,7 @@ func To(err error) {
8789
// and check the error value. If an error occurs, it panics the error so that
8890
// err2 handlers can catch it if needed. Note! If no err2.Handle or err2.Catch
8991
// exist in the call stack and To1 panics an error, the error is not handled,
90-
// and the app will crash. When using try.To1 functions you should always have
92+
// and the app will crash. When using To1 function you should always have
9193
// proper err2.Handle or err2.Catch statements in the call stack.
9294
//
9395
// defer err2.Handle(&err)
@@ -102,7 +104,7 @@ func To1[T any](v T, err error) T {
102104
// and check the error value. If an error occurs, it panics the error so that
103105
// err2 handlers can catch it if needed. Note! If no err2.Handle or err2.Catch
104106
// exist in the call stack and To2 panics an error, the error is not handled,
105-
// and the app will crash. When using try.To2 functions you should always have
107+
// and the app will crash. When using To2 function you should always have
106108
// proper err2.Handle or err2.Catch statements in the call stack.
107109
//
108110
// defer err2.Handle(&err)
@@ -117,7 +119,7 @@ func To2[T, U any](v1 T, v2 U, err error) (T, U) {
117119
// error) and check the error value. If an error occurs, it panics the error so
118120
// that err2 handlers can catch it if needed. Note! If no err2.Handle or
119121
// err2.Catch exist in the call stack and To3 panics an error, the error is
120-
// not handled, and the app will crash. When using try.To3 functions you should
122+
// not handled, and the app will crash. When using To3 function you should
121123
// always have proper err2.Handle or err2.Catch statements in the call stack.
122124
func To3[T, U, V any](v1 T, v2 U, v3 V, err error) (T, U, V) {
123125
To(err)

0 commit comments

Comments
 (0)