website icon indicating copy to clipboard operation
website copied to clipboard

tour: handle error rather than print both

Open crisman opened this issue 1 year ago • 1 comments

In "tour/methods/20" ("Exercise: Errors") just after the slide explaining "calling code should handle errors by testing whether the error equals nil" the example code in the errors exercise provides a main that calls functions expecting error values and does not check them. Checking error values is the expected go way of doing things and should be shown. In the successful case it is also odd to show the "nil" of no error when printing the correct answer (see golang/tour#273). Printing the likely undefined float64 root value when there is an error is also confusing.

Update "methods/exercise-errors.go" and matched solution to only print error on error and only root otherwise.

Fixes golang/tour#273 Fixes golang/tour#230

crisman avatar Mar 20 '23 03:03 crisman

This PR (HEAD: 625960b11fa6fd9fe3fcda1d1c25339f31749082) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/website/+/477615 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off) See the Wiki page for more info

gopherbot avatar Mar 20 '23 03:03 gopherbot