@@ -130,7 +130,7 @@ Simplest rule for err2 error handlers are:
130
130
1. Use ` err2.handle ` functions different calling schemes to achieve needed
131
131
behaviour. For example, without no extra arguments ` err2.Handle `
132
132
automatically annotates your errors by building annotations string from the
133
- function's current name: ` doSomething → " do something" ` . Default is decamel
133
+ function's current name: ` doSomething → " do something: " ` . Default is decamel
134
134
and add spaces. See ` err2.SetFormatter ` for more information.
135
135
1. Every function which uses err2 for error-checking should have at least one
136
136
error handler. The current function panics if there are no error handlers and
@@ -139,7 +139,7 @@ Simplest rule for err2 error handlers are:
139
139
140
140
See more information from ` err2.Handle ` 's documentation. It supports several
141
141
error-handling scenarios. And remember that you can have as many error handlers
142
- per function as you need, as well as you can chain error handling functions per
142
+ per function as you need. You can also chain error handling functions per
143
143
` err2.Handle ` that allows you to build new error handling middleware for your
144
144
own purposes.
145
145
@@ -151,14 +151,15 @@ The err2 offers optional stack tracing. It's *automatic* and *optimized*.
151
151
152
152
<details>
153
153
<summary>The example of the optimized call stack:</summary>
154
+ <br/>
154
155
155
156
Optimized means that the call stack is processed before output. That means that
156
157
stack trace *starts from where the actual error/panic is occurred*, not where
157
158
the error or panic is caught. You don't need to search for the line where the
158
159
pointer was nil or received an error. That line is in the first one you are
159
160
seeing:
160
161
161
- ` ` ` sh
162
+ ` ` `
162
163
---
163
164
runtime error : index out of range [0 ] with length 0
164
165
---
@@ -169,7 +170,7 @@ main.main()
169
170
/home/.../go /src/github.com /lainio/ic/main.go :77 +0x248
170
171
` ` `
171
172
172
- </details><br/>
173
+ </details>
173
174
174
175
Just set the ` err2.SetErrorTracer ` or ` err2.SetPanicTracer ` to the stream you
175
176
want traces to be written:
@@ -185,8 +186,8 @@ the most cases proper error messages are enough and panics are handled
185
186
immediately by a programmer.
186
187
187
188
> [!NOTE]
188
- > Since v0.9.5 you can set these asserters through Go's standard flag package
189
- > just by adding ` flag.Parse ()` to your program . See more information from
189
+ > Since v0.9.5 you can set *tracers* through Go's standard flag package just by
190
+ > adding ` flag.Parse ()` call to your source code . See more information from
190
191
> [Automatic Flags](#automatic-flags).
191
192
192
193
[Read the package documentation for more
@@ -221,17 +222,20 @@ internal packages and certain types of algorithms.
221
222
<br/>
222
223
223
224
In cases where you want to handle the error immediately after the function call
224
- return you can use Go's default ` if ` statement. However, ` defer err2.Handle (&err)`
225
- for all of your error handling.
225
+ you can use Go's default ` if ` statement. However, we recommend you to use
226
+ ` defer err2.Handle (&err)` for all of your error handling, because it keeps your
227
+ code modifiable, refactorable, and skimmable.
226
228
227
229
Nevertheless, there might be cases where you might want to:
228
- 1. Suppress the error and use some default value.
230
+ 1. Suppress the error and use some default value. In next, use 100 if ` Atoi`
231
+ fails:
229
232
` ` ` go
230
233
b := try.Out1 (strconv.Atoi (s)).Catch (100 )
231
234
` ` `
232
- 1. Just write logging output and continue without breaking the execution.
235
+ 1. Just write logging output and continue without breaking the execution. In
236
+ next, add log if ` Atoi` fails.
233
237
` ` ` go
234
- b := try.Out1 (strconv.Atoi (s)).Logf (" %s => 100" , s)
238
+ b := try.Out1 (strconv.Atoi (s)).Logf (" %s => 100" , s). Catch ( 100 )
235
239
` ` `
236
240
1. Annotate the specific error value even when you have a general error handler.
237
241
You are already familiar with ` try.To ` functions. There's *fast* annotation
@@ -241,11 +245,11 @@ Nevertheless, there might be cases where you might want to:
241
245
// where original were, for example:
242
246
b := try.To1 (io.ReadAll (r))
243
247
` ` `
244
- 1. You want to handle the specific error value, let's say, at the same line or
245
- statement. In below, the function ` doSomething` returns an error value. If it
246
- returns ` ErrNotSoBad` , we just suppress it. All the other errors are send to
247
- the current error handler and be handled there, but are annotated with
248
- 'fatal' prefix before that.
248
+ 1. You want to handle the specific error value at the same line or statement. In
249
+ below, the function ` doSomething` returns an error value. If it returns
250
+ ` ErrNotSoBad` , we just suppress it. All the other errors are send to the
251
+ current error handler and will be handled there, but are also annotated with
252
+ 'fatal' prefix before that here .
249
253
` ` ` go
250
254
try.Out (doSomething ()).Handle (ErrNotSoBad, err2.Reset ).Handle (" fatal" )
251
255
` ` `
@@ -388,7 +392,7 @@ of the actual Test function, **it's reported as a standard test failure.** That
388
392
means we don't need to open our internal pre- and post-conditions just for
389
393
testing.
390
394
391
- </details><br/>
395
+ </details>
392
396
393
397
**We can share the same assertions between runtime and test execution.**
394
398
0 commit comments