这可能有点难以遵循。JavaScript异常/错误处理不工作
我已经有了对象内的函数:
f_openFRHandler: function(input) {
console.debug('f_openFRHandler');
try{
//throw 'foo';
DragDrop.FileChanged(input);
//foxyface.window.close();
}
catch(e){
console.error(e);
jQuery('#foxyface_open_errors').append('<div>Max local storage limit reached, unable to store new images in your browser. Please remove some images and try again.</div>');
}
},
try块调用内:
this.FileChanged = function(input) {
// FileUploadManager.addFileInput(input);
console.debug(input);
var files = input.files;
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (!file.type.match(/image.*/)) continue;
var reader = new FileReader();
reader.onload = (function(f, isLast) {
return function(e) {
if (files.length == 1) {
LocalStorageManager.addImage(f.name, e.target.result, false, true);
LocalStorageManager.loadCurrentImage();
//foxyface.window.close();
}
else {
FileUploadManager.addFileData(f, e.target.result); // add multiple files to list
if (isLast) setTimeout(function() { LocalStorageManager.loadCurrentImage() },100);
}
};
})(file, i == files.length - 1);
reader.readAsDataURL(file);
}
return true;
LocalStorageManager.addImage电话:
this.setItem = function(data){
localStorage.setItem('ImageStore', $.json_encode(data));
}
localStorage.setItem如果使用了太多的本地存储,则会引发错误。我想在f_openFRHandler(第一个代码示例)中捕获该错误,但是它将被发送到错误控制台而不是catch块。我尝试下面的代码在我的Firebug的控制台来确保我没有疯,它工作正常,尽管功能嵌套的许多层面:
try{
(function(){
(function(){
throw 'foo'
})()
})()
}
catch(e){
console.debug(e)
}
任何想法?
这是一个很好的例子,它提出了一个关于复杂情况的简洁问题。好一个。 – 2010-06-15 08:03:18
啊,我应该看到的。谢谢你们的帮助。 – 2010-06-16 02:38:09
án:如果以下答案之一帮助您解决了问题,请点击答案顶部左边的复选标记以接受其中一个答案。这标志着“回答”的问题。 (http://stackoverflow.com/faq) – 2010-06-16 09:14:07