课程: Go Practice: Error Handling

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Error handling in goroutines

Solution: Error handling in goroutines - Go教程

课程: Go Practice: Error Handling

Solution: Error handling in goroutines

- [Instructor] And I'm going to show you an example of how you would solve this in Go. So the first thing we're going to do is create the channel string object that we will be returning at the end of this function. So we'll call this result, and we will initialize it using the make function, and we will pass in the chan and string keywords. And then at the end, we want to return result. Next, we're going to actually create the Go routine function. So we'll use the keywords go func. And within the curly brackets, we will first see if there is an error from the isEven function that we pass in the number. If the error isn't nil, that means that the number is actually even, we will set the results to be equal to a string that is essentially going to be an error message, and we'll pass in %v for the error object that we will be calling at runtime. If there isn't an error, then the result is going to be a different string that…

内容