Golang log.Panic, Panicf and Panicln functions example
package log
Golang log.Panic, Panicf and Panicln functions usage example
package main
import (
"fmt"
"log"
)
func main() {
defer func() {
if err := recover(); err != nil {
fmt.Println(err) // nooo! and stop
handleException()
}
}()
log.Panic("nooo! and stop")
// log.Panicf is similar to fmt.Printf ( can replace %s,%v,%d with values)
// log.Panicln is similar to fmt.Println (end of with \n)
log.Println("this will not be called.")
}
func handleException() {
log.Println("recovering...")
}
References :
http://golang.org/pkg/log/#Panic
Advertisement
Something interesting
Tutorials
+6.9k Nginx : Password protect a directory/folder
+13.3k Golang : Linear algebra and matrix calculation example
+25.8k Golang : Daemonizing a simple web server process example
+5.4k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+8.8k Golang : Take screen shot of browser with JQuery example
+8.8k Golang : Random integer with rand.Seed() within a given range
+5.9k Golang : Use NLP to get sentences for each paragraph example
+16.5k Golang : Execute terminal command to remote machine example
+5.1k Golang : Check if a word is countable or not
+5.6k PHP : Fix Call to undefined function curl_init() error
+6.5k Elasticsearch : Shutdown a local node
+23.1k Golang : simulate tail -f or read last line from log file example