javascript - Unnecessary Uncaught, unspecified "error" event - Stack Overflow

In node.js, when I call:throw 'no handler error';when the error happens, I get this message f

In node.js, when I call:

throw 'no handler error';

when the error happens, I get this message from node.js:

events.js:87
      throw Error('Uncaught, unspecified "error" event.');
            ^
Error: Uncaught, unspecified "error" event.
    at Error (native)
    at emit (events.js:87:13)

How can Node.js not retrieve the message 'no handler error' ? I get the same problem when I call 'throw new Error('no handler error');'

How do I create an error message that can retrieved upon invocation? Seems crazy that node.js would allow me to define the error message without ever being able to see it later?

In node.js, when I call:

throw 'no handler error';

when the error happens, I get this message from node.js:

events.js:87
      throw Error('Uncaught, unspecified "error" event.');
            ^
Error: Uncaught, unspecified "error" event.
    at Error (native)
    at emit (events.js:87:13)

How can Node.js not retrieve the message 'no handler error' ? I get the same problem when I call 'throw new Error('no handler error');'

How do I create an error message that can retrieved upon invocation? Seems crazy that node.js would allow me to define the error message without ever being able to see it later?

Share Improve this question edited Apr 27, 2015 at 21:15 Alexander Mills asked Apr 27, 2015 at 20:58 Alexander MillsAlexander Mills 101k166 gold badges539 silver badges919 bronze badges 1
  • this might be irrelevant but have you seen this? - github./Automattic/mongoose/issues/4847 might solve the error. Who knows. Good luck. – Pramesh Bajracharya Commented Jun 17, 2017 at 15:30
Add a ment  | 

2 Answers 2

Reset to default 3

The throw should be like :

throw new Error('No handler error');

BUT : You should only throw fatal errors... For other errors, you should return a callback with the error :

function dummy(next) {
  err = True;
  if(err) return next(new Error('No handler error'));
  return next(null, data);
}

or emit an "error" event on an EventEmitter

A great informations about when you have to throw, when do you use a callback or an event !

https://www.joyent./developers/node/design/errors

You are throwing a string instead of an error, you should probably do something like this:

throw new NoHandlerError();

And define your NoHandlerError somewhere in your library depending on how you are structuring it.

EDIT Upon a good ment suggestion made by @enl8enmentnow

throw new Error ("no handle error"); 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745528376a4631578.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信