我的代码如下,为什么会出现这样的错误;
“ ReferenceError:未定义err”
else if (processMethod.toUpperCase() === "COVID") {
console.log("white", "get covid statics...");
targetCountry = (await covid.parseCountry(UK)).countryid;
if (err.message === "Failed to get country." || err.message === "Invalid Country Code") {
const ErrMsg2 = new Discord.RichEmbed()
ErrMsg2.setColor(0x00AE86)
ErrMsg2.setTimestamp()
ErrMsg2.setAuthor(message.author.username, message.author.avatarURL)
ErrMsg2.setThumbnail(message.guild.iconURL)
ErrMsg2.setDescription(`Failed Try Again`)
ErrMsg2.setFooter("COVID SERVICES")
message.channel.sendEmbed(ErrMsg2);
}
}
答案 0 :(得分:1)
如果要执行错误处理,则需要首先检测错误,请尝试使用try{}
和catch(){}
输入您的代码
try {
targetCountry = (await covid.parseCountry(UK)).countryid;
}
catch (err) {
if (err.message === "Failed to get country." || err.message === "Invalid Country Code") {
// ...
}
}