Why is `.catch(err => console.error(err))` discouraged?

前端 未结 5 1098
别跟我提以往
别跟我提以往 2021-01-30 19:47

I\'m using promises and have code that looks like the following:

function getStuff() { 
  return fetchStuff().then(stuff => 
    process(stuff)
  ).catch(err          


        
5条回答
  •  梦如初夏
    2021-01-30 20:34

    The most general statement here, that applies in languages beyond javascript, is don't 'catch' an error unless you plan to 'handle' the error. Logging is not handling.

    i.e. In general, the best (only?) reason for a catch is to handle/'deal with' the error in a constructive way that allows the code to carry on without any further problems. And again, a line of logging probably never achieves that...

提交回复
热议问题