Contents
15. Panic_Recover(异常捕获)¶
15.1. Python¶
try:
raise Exception('Shit')
except Exception as e:
print("error was:", e)
15.2. Go¶
package main
import "fmt"
func main() {
// Running this will print out:
// error was: Shit!
defer func() {
fmt.Println("error was:",recover()) //error was: Shit!
}()
panic("Shit!")
}