Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 函数后的捕获_Javascript - Fatal编程技术网

Javascript 函数后的捕获

Javascript 函数后的捕获,javascript,Javascript,我以前从未使用过.catch,而且我在网上读到的文档也没有多大意义 这一行: steve.open(req.params.url).then(function(site) { 我得到这个错误: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(

我以前从未使用过.catch,而且我在网上读到的文档也没有多大意义

这一行:

steve.open(req.params.url).then(function(site) {
我得到这个错误:

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
我从来没有用过。接球之前。有人能帮忙吗

我知道在我的
之后({}
我应该添加一个adda
.catch((e)=>{处理错误})


但是在那条线之后这会是什么样子呢?我似乎无法让它工作

您可以在现有代码之后链接调用
.catch()

steve.open(req.params.url)
     .then(response => { 
         // Do something...
     })
     .catch(error => { 
         // Handle the error... 
     });
或者,您可以在对
的调用中声明错误回调。然后()

有一点不同:将多个调用链接到
。然后()
将具有不同的错误处理行为,这取决于您是在单个调用中提供错误回调,还是在链的末尾调用
.catch()


承诺是一个复杂的主题,我建议您在中阅读更多关于承诺的内容。

Hi Max,
。catch
是承诺API的一部分。你可能需要花一点时间来理解这些承诺。查看此JavaScript承诺或搜索“JavasScript承诺教程”了解更多信息!
steve.open(req.params.url)
     .then(response => { 
         // Do something... 
     }, error => { 
         // Handle the error... 
     });