Skip to content

Commit 24c769d

Browse files
committed
added new error logging using go's standard logger, exited the programme if the error occoured
1 parent fb3e495 commit 24c769d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

error_handling/car/car.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
)
77

88
func StartCar(carName string) (string, error) {
9+
910
if carName == "" {
1011
return "", errors.New("there has been some error! Cannot send empty car name")
1112
}

error_handling/driver/driver.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ package main
33
import (
44
"fmt"
55

6+
"log"
7+
68
"aniket-batabyal.com/car"
79
)
810

911
func main() {
10-
fmt.Println("Hey I am a driver")
11-
message, error := car.StartCar("Ford Mustang")
12+
// This says that set a prefix everytime you land in an error
13+
log.SetPrefix("######====> ")
14+
// This disables ot
15+
log.SetFlags(0)
16+
17+
message, error := car.StartCar("")
1218

1319
if error != nil {
14-
fmt.Println(error)
20+
// this prints the error and exits the application by setting os.Exit(1)
21+
log.Print("A lot of errors is not good for your health")
22+
log.Fatal(error)
1523
}
16-
fmt.Println("The message is: ", message)
24+
fmt.Println(message)
1725
}

0 commit comments

Comments
 (0)