Error Handling in Golang
Introduction
Errors and error handling are two very important Go topics. Go likes error messages so much that it has a separate data type errors, names error. This also means that you can easily create your own error messages if you find that what Go gives you is not adequate.
You will most likely need to create and handle your own errors when you are developing your own Go packages.
Please note that having an error condition is one thing, but deciding how to react to an error condition is a totally different thing. Putting it simply, not all error conditions are created equal, which means that some error conditions might require that you immediately stop the execution of a program, whereas other error situations might require printing a warning message for the user to see while continuing the execution of the program. It is up to developer to use common sense and decide what to do with each error value the program might get.
Errors in Go are not like exceptions or errors in other programming languages; they are normal Go objects that get returned from functions or methods just like any other value.
The error data type
There are many scenarios where you might end up having to deal with a new error case while you are developing your own Go application. The error data type is here to help you to define your own errors.
This section will teach you how to create your own error variables. As you will see, in order to create a new error variable, you will need to call the New() function of the errors standard Go package.
Error Handling
Error handling is a very important feature of Go because almost all Go functions return an error message or nil, which is the Go way of saying whether there was an error condition while executing a function.
Thanks for reading :)