Error Handling in JavaScript (Golang Style)
In this short article, we are going to see how we can handle error in JavaScript in Golang style.
I am assuming, you have some experience with JavaScript and you are aware of the issues with error handling like throwing an exception to the parent met...
blog.bibekkakati.me2 min read
Nice, I dig it! Thanks Bibek Kakati!
I’d like to chime in with a minor yet potential improvement.
const getData = async () => { try { const result = await methodCall(); return { result }; } catch(error) { return { error }; } } const { result, error } = getData(); if (error) { // … }IMO returning an object (and destructuring both
resultanderror) is way more readable & explicit.