Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling #2 #12

Open
amanuel2 opened this issue Apr 1, 2016 · 3 comments
Open

Error Handling #2 #12

amanuel2 opened this issue Apr 1, 2016 · 3 comments

Comments

@amanuel2
Copy link

amanuel2 commented Apr 1, 2016

This is just a suggestion...

Instead of doing this all the time:

if err!=nil{
  panic(err);
}

why not make a function...

func check(e error){
 if e!=nil{
   panic(e)
  }
}

Im asking this since i dont exactly know how to make a pull request..

@apkrieg
Copy link

apkrieg commented Apr 11, 2016

You wouldn't always want to panic when handling errors. In simple example apps there is no need to recover from a failure, but when you are developing an application that has real-world purpose you would want to handle and recover from errors. So you would recover in the if statement. If you really want to use the check function you could maybe modify it like this:

func check(e error, callback func(e error)) {
  if e != nil {
    callback(e)
  }
}

and then handle errors like this:

check(err, func(e error) {
  tryAgain()
})

Hope this helps :)

@amanuel2
Copy link
Author

Yea @apkrieg you can manupilate it how you want it. But im just asking if you guys want to change it so there isnt a

if e!=nil{
//DoStuff
}

Just make a function so it dosent get repetitive and its good/clean code.

@riscie
Copy link

riscie commented Apr 15, 2016

I saw this recommendation before @amanuel2
Have to say I like it the way todd does it, because it does not hide our error handling. When reading code I can read what we do when an error occurs which often is quite important. Works better with my reading flow also.

In the end it's a matter of style i guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants