Bug Tracker

Opened 10 years ago

Closed 10 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:


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) {
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');

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 10 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.


Note: See TracTickets for help on using tickets.