[node.js] async/await如何优雅处理异常?
node.js的世界,从callback开始,不会止于async. 所有人都在骂为什么不能完全进化,其实我感觉这就是老外的细心,为了承上。这也就是为什么async其实就是promise一样,假如不是一样的东西,如何承上启下。node.js异常处理一直为人诟病,其实为什么不能优雅心里没有*数吗?这就是设计得辣鸡....好吧,我只是一个用辣鸡的辣鸡。 有些东西不能改变,只能自己改变自己。google了一番,我大概找出了2种我自己喜欢的方式。 一、我只是console一下,我不处理。 async function getData(){ const a = await someFunction().catch((error)=>console.log(error)); const b = await someOtherFunction().catch((error)=>console.log(error)); if(a && b ) console.log("some result") } 二、约定法则 const go = async () => { const readFileResult = await sureThing(readFile('some.json')); if (readFileResult.ok) { const { ok, error, data } =