Skip to content

Commit 5706444

Browse files
committed
Package docs on appropriate use (as well as not).
1 parent 190c1d4 commit 5706444

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

try/try.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@
4848
complete picture. Note that 'finally' blocks will never be recorded
4949
(unless of course they raise a new error!), since they are functions that
5050
return normally.
51+
52+
A note about use cases: while `try` should be familiar and comfortable
53+
to users of exceptions in other languages, and we feel use of a "typed"
54+
panic mechanism results in effective error handling with a minimization
55+
of boilerplate checking error return codes... `try` and `panic` are not
56+
always the correct answer! There are at least two situations where you
57+
may want to consider converting back to handling errors as regular values:
58+
If passing errors between goroutines, of course you need to pass them
59+
as values. Another situation where error returns are more capable than
60+
panics is when part of multiple-returns, where the other values may have
61+
been partially assembled and still may need be subject to cleanup by the
62+
caller. Fortunately, you can always use `CatchAll` to easily fence a block
63+
of panic-oriented code and convert it into errors-by-value flow.
5164
*/
5265
package try
5366

0 commit comments

Comments
 (0)