Created
October 26, 2017 06:07
-
-
Save lamarmarshall/f13bccdc7b5552df512e9b4e8b4f675e to your computer and use it in GitHub Desktop.
go paniic recover
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
fmt.Println("program started to run") | |
testpanic() | |
fmt.Println("program ended") | |
} | |
func testpanic() { | |
defer func() { | |
if err := recover(); err != nil { | |
fmt.Println(err) | |
fmt.Println("we recovered from the error") | |
} | |
}() | |
// throw exception | |
panic("this shit blew up !!!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment