mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-11-28 17:19:06 +00:00
ch5-10 fmt code
This commit is contained in:
parent
5c288d0893
commit
45b04fc567
@ -35,15 +35,15 @@ deferred函數幫助Parse從panic中恢複。在deferred函數內部,panic val
|
|||||||
func soleTitle(doc *html.Node) (title string, err error) {
|
func soleTitle(doc *html.Node) (title string, err error) {
|
||||||
type bailout struct{}
|
type bailout struct{}
|
||||||
defer func() {
|
defer func() {
|
||||||
switch p := recover(); p {
|
switch p := recover(); p {
|
||||||
case nil:
|
case nil:
|
||||||
// no panic
|
// no panic
|
||||||
case bailout{}:
|
case bailout{}:
|
||||||
// "expected" panic
|
// "expected" panic
|
||||||
err = fmt.Errorf("multiple title elements")
|
err = fmt.Errorf("multiple title elements")
|
||||||
default:
|
default:
|
||||||
panic(p) // unexpected panic; carry on panicking
|
panic(p) // unexpected panic; carry on panicking
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
// Bail out of recursion if we find more than one nonempty title.
|
// Bail out of recursion if we find more than one nonempty title.
|
||||||
forEachNode(doc, func(n *html.Node) {
|
forEachNode(doc, func(n *html.Node) {
|
||||||
|
Loading…
Reference in New Issue
Block a user