所以在我的应用程序发生特定情况时,我想显示一个警报,然后停止程序执行。我在某处读到这可以用throw()完成,但我无法完成这项工作。在错误情况下停止JavaScript程序操作?
这是我已经试过:
function check_for_error(data) {
try {
if (<error condition>) {
throw "error";
}
} catch(e) {
alert('error occured');
// I want program execution to halt here but it does not,
// it continues within the calling code
}
}
您可以尝试从catch块中抛出错误,然后在callee方法中处理它。基本上退出。 – Sid 2011-12-16 19:10:45