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

Posted on 2009-12-27
Last Modified: 2012-08-13

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

Question by:waffe
    LVL 11

    Accepted Solution

    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.

    Author Comment

    ok, no time to figure that out - but thanks for the info.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question ( on how to make a page show some balloons animate up a page…
    In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now