Bug Tracker

Opened 6 years ago

Closed 6 years ago

#13782 closed bug (wontfix)

Uncaught exception in event handler will prevent subsequent script executing

Reported by: caikanxp Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

Uncaught exception in event handler will prevent subsequent script executing.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<button id="dom">DOM attached</button>
<button id="jq">jQuery attached</button>
<script type="text/javascript">
<!--
function log(msg) {
	console.log(msg);
	$('<div>').text(msg).appendTo('body');
}
with ($('#dom')[0]) {
	addEventListener('click', function() {
		log('DOM 1');
	});
	addEventListener('click', function() {
		null.log('DOM 2'); // throw an exception
	});
	addEventListener('click', function() {
		log('DOM 3');
	});
}
$('#jq').click(function(e) {
	log('jQuery 1');
}).click(function(e) {
	null.log('jQuery 2'); // throw an exception
}).click(function(e) {
	log('jQuery 3');
});
//-->
</script>

Chrome 26 jQuery 1.9.1

Click button "DOM attached", all 3 handlers will be called. Output:

jQuery 1
[Uncaught Error]
jQuery 2

Click button "jQuery attached", the last handler will not run. Output:

jQuery 1
[Uncaught Error]

IE attachEvent() has similar results, but only in an opposite execution order.

jsfiddle: http://jsfiddle.net/dAKJY/

Change History (1)

comment:1 Changed 6 years ago by timmywil

Resolution: wontfix
Status: newclosed

In order to continue subsequent callbacks, jQuery would have to catch the error, which is not a good solution. If an error is acceptable, a try/catch can be implemented by the user.

http://jsfiddle.net/timmywil/dAKJY/1/

Note: See TracTickets for help on using tickets.