gpt4 book ai didi

javascript - 如何判断 javascript 中的函数调用是否发生错误?

转载 作者:行者123 更新时间:2023-12-03 11:34:46 25 4
gpt4 key购买 nike

我有以下代码结构:

callFunction()

if (there was an error in callFunction()){
//Execute code
}

我可以用什么来代替“callFunction() 中出现错误”来告诉我该函数中调用了一个错误?我应该向 callFunction 本身添加一行吗?

最佳答案

try catch 是一种方法。 http://www.w3schools.com/js/js_errors.asp

例如:

function myFunction() {

try {
//some code to execute
}
catch (e) {
//throw an alert message if the try statement failed
alert(e.toString());
}
}

关于javascript - 如何判断 javascript 中的函数调用是否发生错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26567821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com