On Sat, Jun 1, 2013 at 12:09 PM, revin <caoyunbin...@126.com> 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...
That's the expected and correct behavior: req.on('data') only installs the event listener, it isn't called until the current execution scope (and hence the try/catch block) has ceased to exist. Listen for asynchronous error events with req.on('error'). -- -- 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 nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com 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 nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.