В вашей функции, используя Обещание:
// Function using the Promise
function calc() {
add(1, 3)
.then(res => add(res, 3))
.then(res => add(res, null))
.then(res => console.log('Final result: '+res))
.catch(err => {
// This error is thrown in console
---> throw new Error('Something went horribly wrong')
})
}
Строка, помеченная --->
, выдает ошибку. Эта ошибка не обнаружена. Обычно, когда вы ловите ошибку, вы хотите что-то с ней сделать. Если вы отбрасываете его назад или выкидываете другую ошибку, этот бросок должен быть пойман.
Я бы сделал следующее:
// Function using the Promise
function calc() {
return add(1, 3)
.then(res => add(res, 3))
.then(res => add(res, null))
.then(res => console.log('Final result: '+res))
.catch(err => {
// This error is thrown in console
throw new Error('Something went horribly wrong')
})
}
calc().catch(err => {
console.log(error.message); // For example
});