51. Go - Error Handling
Error Handling is used with functions that returns an err. Uses second variable comma declarations. Example: print , err := fmt. Println ( "HELLO" ) if err != nil { fmt. Println ( "ERROR" ) } Ways to Print Errors: fmt. Println (wgs, "FINISHED" ) print , err := fmt. Println ( "HELLO" ) if err != nil { fmt. Println ( "ERROR" ) log. Println ( "ERROR" ) log. Fatal () log. Fatalf ( "ERROR" ) log. Fatalln ( "ERROR" ) log. Panic () log. Panicf ( "ERROR" ) log. Panicln ( "ERROR" ) } // Fatal exists program.. // Panic is mid serious, does not exit program and have ability to recover. // Log gives ability to log the error into a file. // fmt.print, prints error to standard output. Logging // prints or outputs into a designated file. package main import ( "fmt" "log"