在go中recover之后怎么返回error

package main

import (
    "fmt"
    "math"
)

func main() {
    _, err := IntFromInt64(math.MaxInt32 + 1)
    if err != nil {
        fmt.Println(err)
    }
}

func ConvertInt64ToInt(i64 int64) int {
    if math.MinInt32 <= i64 && i64 <= math.MaxInt32 {
        return int(i64)
    }
    panic("can't convert int64 to int")
}

func IntFromInt64(i64 int64) (int, error) {
    defer func() {
        if err := recover(); err != nil {
            return 0, fmt.Errorf("%v", err)
        }
    }()
    i := ConvertInt64ToInt(i64)
    return i, nil
}

defer func()中recover之后怎么返回

查看回复