-
Book Overview & Buying
-
Table Of Contents
Building Microservices with Go
By :
One of the great things about Go is that the standard patterns are such that you should always handle errors when they occur, instead of bubbling them up to the top and presenting them to the user. Having said that, there is always a case when the unexpected happens. The secret to this is to know about it and to fix the problem when it occurs. There are many exception logging platforms on the market. However, the two techniques we have discussed are, in my opinion, more than sufficient for tracing the few errors that we hopefully will find in our web application.
Go has two great methods for handling unexpected errors:
panicrecoverThe built-in panic function stops the normal execution of the current goroutine. All the deferred functions are run in the normal way; then, the program is terminated:
func panic(v interface{}) The recover function allows an application to manage the behavior of a panicking goroutine. When called inside a deferred function,...
Change the font size
Change margin width
Change background colour