Error-Handling and Panicking in a User-Defined Package
This lesson provides an implementation and a detailed explanation about catching errors in custom packages and recovering programs in case of a panic.
Here are a couple of best practices which every writer of custom packages should apply:
- Always recover from panic in your package: no explicit
panic()
should be allowed to cross a package boundary. - Return errors as error values to the callers of your package.
This is nicely illustrated in the following code:
Get hands-on with 1200+ tech skills courses.