我有以下代码结构:
callFunction()
if (there was an error in callFunction()){
//Execute code
}
我可以用什么代替'callFunction()中的错误,它会告诉我在该函数中调用了错误?我应该添加到callFunction
本身的行吗?
答案 0 :(得分:1)
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());
}
}