admin管理员组文章数量:1430608
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
2 Answers
Reset to default 3The 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");
本文标签: javascriptUnnecessary Uncaughtunspecified quoterrorquot eventStack Overflow
版权声明:本文标题:javascript - Unnecessary Uncaught, unspecified "error" event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745528375a2661944.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论