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");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745528376a4631578.html
评论列表(0条)