On 2 June 2013 at 6:48:13 AM, revin ([email protected]) wrote:
OK,thanks guys,
what I've posted is trying to simplify the question,
this is the real problem:
Yes indeed, try{...} frame "is" work on the "execution flow (stack trace)",
but that's C, that's C++, that's java!
They're all sync language!
When it comes to nodeJs, shouldn't it be async as well as nodeJs itself?

Let's see a real project:
modules:
httpd.js main module, setup server, dispatch requests.
httpdoc.js helper module, if request is a file (e.g.: /index.htm), the request 
will be directed from httpd.js to this module
... other modules
REQUEST => httpd.js =(ANALYSE,DISPATCH)=> httpdoc.js

we should handler all errors inside httpd.js:
file not found: respond 404
access denied: respond 404
file IO failure: respond 500
internal error: respond 500
other responds...

then in httpdocs.js:
fs.ReadStream("...").on("error",function(e){
  throw e;
});
The real question is "Why throw?"
If you read "throw" as "unwind the stack and handle errors at a higher call 
site", and know that async code has already unwound the stack and started 
something anew, throw doesn't look like the right tool. It's just a tool -- 
there are other approaches.
How about calling an error handler on something defined in your httpd.js? 
That's a simple approach -- make all of those sub-handlers pass their errors on.
Another, more robust approach that's been baked into node core more recently is 
to use error domains: If you set all of your EventEmitter's domain property to 
a domain, the domain's error handler will fire for all errors in that domain. 
Still fully async.
[snip]
But since nodeJs follows the definition of try{...} after some sync languages,
rather than to start a new one for async languages like nodeJs itself,
these code won't run like expected.
Indeed: node is just javascript -- it has not extended the language at all, so 
the concepts are the same. try/catch is synchronous, still only concerned with 
the regular execution stack.
Could any one come up with a solution?
How to catch exceptions on event callbacks?
Please don't say that you can setup an uncaught exception handler,
there can be only one of it,
And that's where you're wrong: error domains give you an uncaught exception 
handler for each separate domain.

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to