Go Programming by Example by Agus Kurniawan

Go Programming by Example by Agus Kurniawan

Author:Agus Kurniawan
Language: eng
Format: epub
Published: 2015-02-22T16:00:00+00:00


Now you can this program.

You can see function under defer run completely. When we call panic(), Go will raise error on our program and then stopped this program.

Now how to catch error on Go program? we can use recover() to catch error.

Try to create calculaze2() function, and write this code.

package main import ( "fmt" ) func main(){ calculate2() } func calculate2() { fmt.Println("----demo error handling---") c := 0 defer func() { a := 10 b := 0 c = a/b if error := recover(); error != nil { fmt.Println("Recovering....", error) fmt.Println(error) } }() fmt.Printf("result = %d \n",c) fmt.Println("Done") }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.