Functions and Files
This lesson flashes back to the standard operations and their syntaxes defined on functions and files.
📝 Useful code snippets for functions
Recovering to stop a panic terminating sequence:
func protect(g func()) {
defer func() {
log.Println("done") // Println executes normally even if there is a panic
if x := recover(); x != nil {
log.Printf("run time panic: %v", x)
}
}()
log.Println("start")
g()
}
Get hands-on with 1400+ tech skills courses.