jQuery custom object event handler exception-swallowing regression test case
Demonstrates a regression caused by the fix to jQuery bug #3533. Exceptions thrown in the final `on<event>` handler of a custom object will be swallowed by jQuery.
by josh3736
HTML
Check your console. The error <code>This exception will be swallowed</code> <i>should</i> show up, but the thrown exception is improperly caught by jQuery-1.5.js:2452.
JavaScript
var Test = function() {
this.onclick = function(e) {
console.log('Running onclick');
throw new Error('This exception will be swallowed.');
console.log('...and execution will stop.');
}
this.onsubmit = function(e) {
alert("This won't run because the exception in the bound handler will throw properly.");
}
}
var obj = new Test();
$(obj).click();
$(obj).submit(function() { throw new Error('This will throw'); }).submit();