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
+5.9k Golang : Use NLP to get sentences for each paragraph example
+4.8k PHP : Extract part of a string starting from the middle
+9.1k Golang : Simple histogram example
+6.5k Golang : Spell checking with ispell example
+29.9k Golang : How to get HTTP request header information?
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+26.4k Golang : Get executable name behind process ID example
+12.5k Golang : "https://" not allowed in import path
+18.2k Golang : Put UTF8 text on OpenCV video capture image frame
+9.4k Golang : Qt Yes No and Quit message box example
+10.4k Golang : Generate random integer or float number
+19.9k Golang : Measure http.Get() execution time