I have following code:-
try {
user.findOne({ Email: req.body.email }, function (e, d) {
if (d) {
res.json({
'success': false,
'json': null,
'message': 'This email already exists!',
'status': 200
});
} else {
var u = new user();
u.Email = req.body.email;
u.Password = req.body.password;
u.Name = req.body.name;
user.save(function (e, d) {
res.json(d);
});
}
});
} catch (ex) {
console.log(ex.message + " \n" + ex.stack);
res.json({
'success': false,
'json': ex,
'message': 'Opps! something wen wrong please try again later!',
'status': 500
});
}
}
I have an exception on line user.save(function (e, d) {
I solve the issue but the problem is I see catch block doesn't fire at all and node server stop due to exception. if I put try block inside user.findOne
catch block will be fire can anyone please explain me why this behavior in node application?
Thanks you!