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
+4.8k Facebook : How to place save to Facebook button on your website
+12.3k Golang : Display list of countries and ISO codes
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+5.4k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+8.6k Golang : Progress bar with ∎ character
+6.5k Golang : Combine slices of complex numbers and operation example
+7.9k Golang : Grayscale Image
+13.2k Golang : Convert(cast) int to int64
+33.7k Golang : All update packages with go get command
+31.7k Golang : How to convert(cast) string to IP address?
+6.9k Golang : How to solve "too many .rsrc sections" error?
+7.2k Golang : Dealing with postal or zip code example