簡體   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