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
+16.3k Golang : Find out mime type from bytes in buffer
+22.2k Golang : How to run Golang application such as web server in the background or as daemon?
+5.8k Cash Flow : 50 days to pay your credit card debt
+5.2k Golang : The Tao of importing package
+18.7k Golang : Iterating Elements Over A List
+7k Golang : How to call function inside template with template.FuncMap
+8k Golang : What fmt.Println() can do and println() cannot do
+7.4k Golang : Convert source code to assembly language
+5k Python : Convert(cast) bytes to string example
+20.8k Golang : Convert date string to variants of time.Time type examples
+12.9k Python : Convert IPv6 address to decimal and back to IPv6