DEV Community

Discussion on: Say goodbye Trycatch Hell

Collapse
oysterd3 profile image
Oyster Lee

This is over-engineered to me

Collapse
ivanz123 profile image
Ivan Zadivar Author

It seems like this at first glance, but it will be useful when the use of trycatch becomes repetitive, and these functions allow you to always reuse them.

Collapse
pedro profile image
Pedro M. M. • Edited on

Actually, this error tuple-pattern is very common in Go.

if x, err := doSomething(); err != nil {
   // failed!
}
// worked! Safe to use x.
Enter fullscreen mode Exit fullscreen mode
x, err := doSomething()
if err != nil {
  // failed!
}
// worked! Safe to use x
Enter fullscreen mode Exit fullscreen mode
x, err := doSomething(); err == nil {
  // Do something with x only if doSomething() returns no errors
}
Enter fullscreen mode Exit fullscreen mode
if x, ok := booleanOp(); ok {
    // Do something with x only if ok = true
} 
Enter fullscreen mode Exit fullscreen mode

In terms of error handling, my favorite is rust because it has less overhead. But it's uglier and a little bit more complicated.

Collapse
oysterd3 profile image
Oyster Lee

Yes, I am a gopher, but do you think over 50% JavaScript developer using Go?

Thread Thread
pedro profile image
Pedro M. M. • Edited on

No! Of course not lol.

My point was — If a whole modern language, which is known as an easy-to-read language, uses a pattern like that as standard good practice maybe the pattern is not that over-engineered