admin管理员组文章数量:1327996
I have some code that just has me baffled. I have searched online, and I cannot find anything like this, though I'm not thinking I'm the first =) I'm using dojo, and I don't have any idea if that has anything to do with the problem I'm having. The problem is that Firebug will not throw an error I would like it to throw. However, when debugging it in Safari, the error is thrown??? I do this sort of thing all the time, and for some reason it will not work here.
Here is the code sample:
var formSubmit = function(e) {
e.preventDefault();
var f = testForm.domNode,
map = {};
for(var i = 0; i < f.elements.length; i++){
var elem = f.elements[i];
map[elem.id] = elem.value;
}
if (!map.id && !map.field1) {
***// -- this error will not be thrown --***
throw new Error("you must supply some data");
}
}
testForm = new Form({
encType: "multipart/form-data",
method: "post",
onSubmit: formSubmit
}, "testForm");
Anyone have any ideas as to why this would not work in Firebug?
I have some code that just has me baffled. I have searched online, and I cannot find anything like this, though I'm not thinking I'm the first =) I'm using dojo, and I don't have any idea if that has anything to do with the problem I'm having. The problem is that Firebug will not throw an error I would like it to throw. However, when debugging it in Safari, the error is thrown??? I do this sort of thing all the time, and for some reason it will not work here.
Here is the code sample:
var formSubmit = function(e) {
e.preventDefault();
var f = testForm.domNode,
map = {};
for(var i = 0; i < f.elements.length; i++){
var elem = f.elements[i];
map[elem.id] = elem.value;
}
if (!map.id && !map.field1) {
***// -- this error will not be thrown --***
throw new Error("you must supply some data");
}
}
testForm = new Form({
encType: "multipart/form-data",
method: "post",
onSubmit: formSubmit
}, "testForm");
Anyone have any ideas as to why this would not work in Firebug?
Share Improve this question asked Apr 6, 2012 at 19:33 mikemike 651 silver badge6 bronze badges 4- 1 If it's not thrown then it's [more than likely] not reached. – user166390 Commented Apr 6, 2012 at 19:35
-
1
Is the
formSubmit
function executing at all? – Alex Wayne Commented Apr 6, 2012 at 19:36 - @Ryan If it's a conforming JavaScript engine (I guess it could be shadowed to another value by silly code, but..) – user166390 Commented Apr 6, 2012 at 19:50
- Hi guys. Thanks for your input. I appreciate it more than you know. The code is executing within the if statement. I can put an console.log statement in there, and it will be output in firebug, but the error won't be displayed. Also, the exact same code in Safari's debugging tools will display the error...that's what's most confusing to me. – mike Commented Apr 6, 2012 at 22:40
1 Answer
Reset to default 8The error probably is thrown, but the function that throws the error is being called from an event handler so the error ends up in the system event handling code where it's either caught there (not caught in your code) or it simply gets ignored.
When you say, "it's not thrown", what were you expecting to see? Did you have a try/catch
somewhere that you were expecting to catch the exception? Throwing an exception doesn't have any generic UI of it's own. It throws the exception and then it's up to some higher level code to catch the exception and do something with it. If there is no higher level code in that event loop to catch the exception, then it just aborts the execution of that event handler.
本文标签: Javascript will not throw a new ErrorStack Overflow
版权声明:本文标题:Javascript will not throw a new Error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742249834a2440541.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论