繁体   English   中英

捕获错误的正确方法是什么?

[英]What is the correct way of catching an error?

如何为错误消息设置变量? 这是我的代码:

 .catch(console.error).then((err) => {
  var x = err.message;
 )};

我收到此错误:

无法读取未定义的属性“消息”

您在catch调用中得到错误:

.catch((err) => {
    console.error(err);
    var x = err.message;
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM