Exception handling is one of the reasons why I wrote streamline.js:
try {
myFunction(_);
console.log('no errors');
} catch(err) {
console.log('error caught: ' + err.message);
}
function myFunction(_){
setTimeout(_, 100);
someFunctionDeepInLibrary(_);
}
function someFunctionDeepInLibrary(_){
throw new Error("Surprise!")
}
To try it, cut and paste to
http://sage.github.com/streamlinejs/examples/streamlineMe/streamlineMe.html
No APIs to learn. Just looks and feels like regular JavaScript.
And streamline does not hide the async points under the carpet. They
surface at all levels as '_' (and the compiler will yell at you if you try
to hide one). If you see a block of code without '_' you know that it runs
to completion. If you see a call with an '_' you know that some other event
might interfere. From my experience this makes it very easy to reason about
race conditions. There is also a handy 'funnel' function to limit
concurrency and protect critical sections.
Bruno
On Saturday, November 10, 2012 6:01:22 AM UTC+1, Alexey Petrushin wrote:
>
> 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