有这样的设计:
try {
fetch(url)
.then(res => res.json())
.then(data => callback(data));
} catch(e) {
console.dir(e);
}
当我故意传递一个 invalidurl时,控制台会打印一个未处理的异常。
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
at <anonymous>:120:28
在这种情况下如何处理异常?
1 个回答