This is a creation in Article, where the information may have evolved or changed.
Fullscreen's error handling can be a tragedy, and it is not conducive to differentiating between errors.
It is recommended that you use custom errors in your project, and then focus on the errors.
Package Main//error Processing Mode demo//author:xiong Chuan liang//date:2015-2-26import "FMT" Import "Errors" Func main () {Errtype ( Test0 ()) Errtype (Test1 ("Test1")) Errtype (Test2 ()) Errtype (Test3 ("Test3")) Errtype (Test4 ("test4"))}type Error1 struct {arg interrmsg string}func (e *error1) Error () string {return FMT. Sprintf ("%s", e.errmsg)}type Error2 struct {arg stringerrmsg string}func (e *error2) Error () string {return FMT. Sprintf ("%s", e.errmsg)}func test0 () error {return errors. New ("errors. New ()-test0 () ")}func test1 (arg string) error {return FMT. Errorf ("FMT. Errorf ()-test1 () ")}func test2 (arg int) *error1 {return &error1{arg," error1{}-Test2 () "}}func test3 (Arg string) err or {return &error2{arg, "error2{}-Test3 ()"}}func test4 (Arg string) *error2 {return &error2{arg, "error2{}-Test 4 () "}}func Errtype (Err interface{}) {switch e: = Err. ( Type) {case *error1:fmt. Println ("Type:error1", e) Case *error2:fmt. Println ("Type:error2", e) Case error:fmt. Println ("Type:error", E) DefaUlt:fmt. Println ("Type:default", e)}}/* operation effect: Type:error errors. New ()-test0 () Type:error FMT. Errorf ()-test1 () Type:error1 error1{}-test2 () Type:error2 error2{}-test3 () Type:error2 error2{}-test4 () */
Mail:xcl_168@aliyun.com
blog:http://blog.csdn.net/xcl168