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
+20.9k PHP : Convert(cast) int to double/float
+18.6k Golang : Generate thumbnails from images
+8.8k Golang : On lambda, anonymous, inline functions and function literals
+9.6k Golang : Copy map(hash table) example
+7.5k Golang : Rot13 and Rot5 algorithms example
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+15.9k Golang : Get current time from the Internet time server(ntp) example
+13.1k Golang : Convert(cast) uintptr to string example
+12.3k Golang : List running EC2 instances and descriptions
+6.4k CodeIgniter : form input set_value cause " to become & quot
+14.4k Golang : How to convert a number to words