My understanding is that a piece of code throwing error anywhere in callstack can be caught at final catch block.
(我的理解是,可以在最终catch块中捕获在调用堆栈中任何地方发生的代码抛出错误。)
for fetch error, when no internet is available, when I make APIwithoutCatch in callCallAPI, error is not caught.(对于获取错误,当没有可用的互联网时,当我在callCallAPI中制作APIwithoutCatch时,未捕获到错误。)
while APIwithCatch catches its own error.(而APIwithCatch会捕获自己的错误。)
All other errors eg 404, are caught at both places, wherever I want.(无论我在哪里,所有其他错误(例如404)都会在这两个地方捕获。)
async function APIwithcatch() { try { var response = await fetch("http://wwww.dfdfdf.com/user.json"); return response; } catch (e) { console.log(e); } } async function APIwithoutcatch() { var response = await fetch("http://wwww.dfdfdf.com/user.json"); return response; } function callCallAPI() { try { // return APIwithcatch(); return APIwithoutcatch(); } catch (e) { console.log(e); } } callCallAPI();
My assumption that any error should flow down callstack is correct or not?
(我的假设是任何错误都应沿着调用堆栈流下来,这是正确的还是错误的?)
What is special about net::ERR_INTERNET_DISCONNECTED error?
(net :: ERR_INTERNET_DISCONNECTED错误有什么特别之处?)
ask by DrEarnest translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…