异常处理

package main

import (
    "fmt"
)

type simpleException struct {
    errText string
}

func (e simpleExceptionError() string {
    return e.errText
}

func throwSimpleException() error {
    return simpleException{"simple exeption"}
}

func main() {
    err := throwSimpleException()

    if err != nil {
        fmt.Println(err)
        //printed: simple exeption
    }
}