Golang builtin.recover() function example
package builtin
The recover built-in function allows a program to manage behavior of a panicking goroutine.
Golang builtin.recover() function usage example
package main
import "fmt"
func startPanic() {
defer func() {
if error := recover(); error != nil {
fmt.Println("Recovering....", error)
}
}()
panic("noooo!")
}
func main() {
fmt.Println("Starting to panic...")
startPanic()
fmt.Println("This will APPEAR because of Recover")
}
Output :
Starting to panic...
Recovering.... noooo!
This will APPEAR because of Recover
Reference :
Advertisement
Something interesting
Tutorials
+5.3k PHP : Hide PHP version information from curl
+4.3k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+6.4k Golang : Break string into a slice of characters example
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+5.3k Swift : Convert string array to array example
+11k How to test Facebook App on localhost ?
+6.1k Golang : How to write backslash in string?
+6.5k PHP : Shuffle to display different content or advertisement
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+31.5k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+15.2k Golang : How to add color to string?
+18.6k Golang : Generate thumbnails from images