Error handling with callbacks is especially interesting, try this code -
the 'Surprise' error won't be caught.
// Catching synchronous errors.
try {
myFunction(function(err){
// Catching asynchronous errors.
if(err) return console.log('error catched')
console.log('no errors')
})
} catch(err) {
console.log('error catched')
}
var myFunction = function(cb){
setTimeout(function(){
someFunctionDeepInLibrary(cb)
}, 100)
}
var someFunctionDeepInLibrary = function(cb){
throw new Error("Surprise!")
}
Live version (open console to see the result) http://tinkerbin.com/axnxQte5
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en