【发布时间】:2014-11-03 18:36:52
【问题描述】:
按照code of the Webkit Speech Recognition(查看源代码),我想在启动时(例如当您拒绝浏览器使用麦克风时)捕获错误以执行其他操作。
问题是……我不知道如何抓住这个错误之王。
最终目标是将错误消息传递给尝试启动 Webkit 语音识别的对象。因此,如果您有另一个(好的)解决方案来做到这一点。
我有这样的关系:
var anObject= {
recognizer : Recognizer,
listen : function() {
try{
this.recognizer.listen();
} catch (error) {
alert('I want to do something here with the error');
}
}
}
var Recognizer = {
listen: function()
{
var recognition = new webkitSpeechRecognition();
// recognition config
try{
recognition.start();
} catch (error) {
alert(error);
// I've also tried "throw error;" but we never pass in this catch
}
recognition.onerror = function(event) {
console.log(event.error); // this works
throw event.error; // the "exception" is thrown
}
// other functions
}
}
这不起作用,我不知道为什么。我得到了一个“未捕获的异常”,所以抛出了异常,但没有被捕获。
感谢您的帮助。
【问题讨论】:
标签: javascript exception webkit speech-recognition