Yes, there is a bug. Using throw in asyncronous programming is a bug indeed.

You're right, "throw" function is in the same context in a sense that it 
can access outer variables (it's called closure). But it is out of the 
execution context in a sense that it doesn't happen in try-catch block.

That's how node.js executes it:
1st phase (starting). 49-50-51(try)-53-54(catch)-55
2nd phase (when data is received). 52

To confirm that you can get a stack trace from function(data) and see where 
it is executed from. It won't be your function(req,res).


On Saturday, June 1, 2013 2:09:54 PM UTC+4, revin wrote:
>
> Hi,there:
>
> There may be a bug in try{...} frame that 
> can't catch exceptions triggered by event listeners inside it.
>
> I'm so interested in nodeJs,
> but since it was young,
> it has a lot of drawbacks.
>
> I've noticed that nodeJs don't have a concurrent api interface,
> so I've decided to write my own framework extension based on nodeJs.
> But soon I've encountered a problem:
> 49:function(req,res){
> 50:try{
> 51:  req.on("data",function(data){
> 52:    throw new Error("FIXME: DebugTrap");
> 53:  }
> 54:}cat1ch(e){}
> 55:}
> I think everyone, of course including me,
> will hope this works,
> but it won't.
>
> The weired thing is,
> when execution reaches line 52,
> it kinds of "inherited" the execution context from line 49,
> see it can access the variables, req and res.
> But the try{...} frame on line 50 can't catch Error on line 52.
>
> It's a V8 problem? Could it be fixed with nodeJs?
> I just don't want to build try{...} frames inside every event listener...
>

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