- From your Terminal/console application,createa new directory called~/projects/go-programming-cookbook/chapter4/panic and navigate to this directory.
- Run the following command:
When implementing long-running processes, it's possible that certain code paths will result in a panic. This is usually common for things such as uninitialized maps and pointers, as well as division by zero problems in the case of poorly validated user input.
Having a program crash completely in these cases is frequently much worse than the panic itself, and so it can be helpful to catch and handle panics.
How to do it...
These steps cover the writing and running of your application:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook-Second-Edition/chapter4/panic
You should see a file calledgo.modthat contains the following:
module github.com...