1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-30 04:30:01 +02:00

add error handling in go, defer, panic, recover (#2126)

* add error handling in go, defer, panic, recover

* Update content/roadmaps/109-golang/content/100-go-basics/106-errors-panic-recover.md

* Update content/roadmaps/109-golang/content/100-go-basics/106-errors-panic-recover.md

Co-authored-by: Matteo Bruno <satboy78@MacBook-Pro-Matteo.local>
Co-authored-by: Kamran Ahmed <kamranahmed.se@gmail.com>
This commit is contained in:
satboy78
2022-10-05 01:01:49 +02:00
committed by GitHub
parent e9c864320c
commit fc925df147

View File

@@ -1 +1,12 @@
# Errors panic recover
# Errors/Panic/Recover
In lieu of adding exception handlers, the Go creators exploited Gos ability to return multiple values. The most commonly used Go technique for issuing errors is to return the error as the last value in a return.
A panic typically means something went unexpectedly wrong. Mostly used to fail fast on errors that shouldnt occur during normal operation, or that we arent prepared to handle gracefully.
Panic recovery in Go depends on a feature of the language called deferred functions. Go has the ability to guarantee the execution of a function at the moment its parent function returns. This happens regardless of whether the reason for the parent functions return is a return statement, the end of the function block, or a panic.
<ResourceGroupTitle>Free Content</ResourceGroupTitle>
<BadgeLink colorScheme='yellow' badgeText='Read' href='https://go.dev/blog/error-handling-and-go'>Error handling and Go</BadgeLink>
<BadgeLink colorScheme='yellow' badgeText='Read' href='https://go.dev/blog/defer-panic-and-recover'>Go Defer, Panic and Recover</BadgeLink>
<BadgeLink colorScheme='yellow' badgeText='Read' href='https://earthly.dev/blog/golang-errors/'>Effective error handling in Go</BadgeLink>