Go: error variable reassigning, proper use? -


I'm confused about re-combinations of the err variable for errors in C.

For example, I am doing this:

  err1: = some () checkErr (err1) str, err2: = SomethingElse () checker err2 err3 : = Something () Check ARR (err3)  

But I'm always losing track of it and I have millions of worthless fault variables that do not need, for which I do not need it, and It makes the code messy and confusing.

But then if I do this:

  err: = some () check array (error) str, err: = SomethingElse () checkErr (err) err: = Some () checks ARR (error)  

... it gets annoying and says err is already assigned.

But if I do this:

  var err err err = something () checkErr (err) str, err = SomethingElse () checkErr (err) err = SomethingAgain () Checker (error)  

... This does not work because str should be assigned with : = < / P>

Am I missing something?

you 'almost' ... again to the left of : = Need to have at least one new variable conversion variable. But if you do not declare fault in advance, then the compiler tries to make it at every frequency of : = , this is the reason that you get the first error example Package: Main import "fmt" func foo () (string, error) {return "bar", zero}, func main () {var err error s1

or in your case:

 

Code> // We forget this for the first time // It's a General assignment is err = something () checkErr (err) // Yes, the compiler knows that only str is a new declared variable str, err: = SomethingElse () CheckErr (err) // and again ... err = SomethingAgain () probes (error)


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -