Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDennis Brown
28,742 PointsError Handling Practices, and/or Rules of Thumb?
I'm starting to see a pattern with error handling, but I wanted to see if it was a coincidence, or how it actually works. With async callbacks, especially in Node.js errors are always the first parameter (when using 4 total). This seems to be the case for closure callback patterns as well.
So, are errors always sent as the first parameter, and is this the default stderr placement? This seems to be the case, but I cannot find anything to prove it, or disprove it. I really want to understand where to expect the stderr anywhere in any of my apps to provide great error handling, and not just in Node.js.
Thanks in advance, even if it is just a link to something with more information. :)
Dennis Brown
28,742 PointsThanks for the input, and great to hear this is also the case with promises. :D
Yes, it was the docs that lead me to that, and definitely not something to do even when knowing it happens to be the way I'm assuming (e.g. can't even be called in Node.js without the "next" param). Still, it would be great to know if there is a set place for the stderr in JS. It just may be time to look deeper into the inner-workings of JS. ;)
1 Answer
Dennis Brown
28,742 PointsOk, to follow up, this it due to "Error-First Functions", which are very common, but not always the case. In terms of Node.js, Promises, and just about anything else Asynchronous, it takes advantage of this function style with the Inversion of Control used with Async functions.
I hope this is helpful for anyone else later on.
Ethan Weeks
15,352 PointsEthan Weeks
15,352 PointsThis might be the "kind of blind" leading the "kind of blind" but I think your on to something. I will have to agree with you that async callbacks that do have an error parameter come first. What is odd is that when creating Promises the first parameter is resolve and second is reject. I know it's different that they are not the actual response but just the callbacks. Either way I will still look at docs before expecting the error to be the first parameter.