Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is it significantly different than a try-catch block?




Yeah it lets you put code that goes in "catch" all over your function body, right next to where it's most relevant. It lets you go "hm but what about errors? ah handled! ok i can forget about it" when reading a function without having to skip back and forth between the main code and the catch block.

> Yeah it lets you put code that goes in "catch" all over your function body, right next to where it's most relevant.

To be fair I’ve rarely seen that, usually you’ve got half the method in a giant try block and have fun untangling which errors are caught intentionally and which are side-effects.


But that's just try blocks around where it's relevant except the more precise scoping of a block and the catch being after where the errdefer is before.

one less level of indentation; reading down is happy path, seems nice!

Huh? But the exceptional behaviors are listed first?

Would you say we should move to catch-try syntax? Seems strange to me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: