Javascript-Phonegap无法从函数中抛出新错误

Javascript-Phonegap无法从函数中抛出新错误,javascript,ios,cordova,error-handling,runtime-error,Javascript,Ios,Cordova,Error Handling,Runtime Error,我无法使用以下代码行从phonegap应用程序中抛出错误: var myBook = ['..an Array of sentences..', '...'] this.getIds = function(sentence){ var index = myBook.indexOf(sentence); if(index == -1) throw new Error(sentence + ' does not appear in the book!'); return i

我无法使用以下代码行从phonegap应用程序中抛出错误:

var myBook = ['..an Array of sentences..', '...']

this.getIds = function(sentence){
    var index = myBook.indexOf(sentence);
    if(index == -1) throw new Error(sentence + ' does not appear in the book!');
    return index;
};

...
this.getIds('this is an invalid sentence');
...
我是不是遗漏了什么?还是我在错误的地方看到抛出的错误?我希望我在Safari的Web Inspector中抛出错误,但在iOS模拟器上测试时没有出现错误

我也试过了

throw 'this sentence does not appear in the book!';
到目前为止没有错误。谢谢你抽出时间


已解决:此问题现在已解决,我已验证抛出错误。看来问题与Phonegap无关毕竟,这只是if检查中的测试条件失败。。我对测试条件非常肯定,我甚至没有考虑改变它和Trimh。现在,这里有一个糟糕的调试实践:感谢大家的关注。

在调用GetID之前,尝试抛出一个错误。“有用吗?”@Baidaly嘿,多亏了你的回答,我解决了我的问题,让它起作用了!我不想把错误抛出函数之外,真是太傻了。我想这可能是电话间隔限制之类的,然后失去了焦点。。。我拥有的实际阵列与这里提供的示例有很大不同。这仅仅是一个测试条件失败,比如:myTestIndex>index。我把它改为myTestIndex>=索引,瞧。。