mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
fix: coding style and file format for all example.
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
// panic_recover.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func badCall() {
|
||||
panic("bad end")
|
||||
}
|
||||
|
||||
func test() {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
fmt.Printf("Panicing %s\r\n", e)
|
||||
}
|
||||
}()
|
||||
badCall()
|
||||
fmt.Printf("After bad call\r\n") // <-- wordt niet bereikt
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf("Calling test\r\n")
|
||||
test()
|
||||
fmt.Printf("Test completed\r\n")
|
||||
}
|
||||
|
||||
/* Output:
|
||||
Calling test
|
||||
Panicing bad end
|
||||
Test completed
|
||||
*/
|
||||
// panic_recover.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func badCall() {
|
||||
panic("bad end")
|
||||
}
|
||||
|
||||
func test() {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
fmt.Printf("Panicing %s\r\n", e)
|
||||
}
|
||||
}()
|
||||
badCall()
|
||||
fmt.Printf("After bad call\r\n") // <-- wordt niet bereikt
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf("Calling test\r\n")
|
||||
test()
|
||||
fmt.Printf("Test completed\r\n")
|
||||
}
|
||||
|
||||
/* Output:
|
||||
Calling test
|
||||
Panicing bad end
|
||||
Test completed
|
||||
*/
|
||||
|
Reference in New Issue
Block a user