try catch not working with $().load();


I am using a simple try catch in JavaScript but the catch is never working even if the .load is pointed to a file that is not there. In the code below the second alert never happens even if I point the first .load() to nothing.
setInterval(function() {
		alert ("try1");
	} catch(err) {
		alert ("try2");
}, 5000);

Open in new window

Who is Participating?
asafadisConnect With a Mentor Commented:
It doesn't work because jQuery doesn't throw exceptions.  In other words, there's nothing to "catch".
You're best bet would be to use $.ajax() instead of $.load(), and put in your "failure scenario" in the "error" option.
waffeAuthor Commented:
ok, no time to figure that out - but thanks for the info.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.