jQuery Ajax异常捕获器

I'm stuck with a simple exception that I can't catch:

//myScript.js.coffee
try
  $.ajax
    async: false
    type: "GET"
    url: index_url
    success: ->
      //Do something
    error: ->
      //Do something else
    fail: ->
      //Do something else
catch e
  console.log e

When I try to call this Ajax with a bad url, there is an error and nothing caught it. Does any one have an idea ?

Basically I would like to test the url before calling this ajax request.

Edit: I know that putting a try/catch with an asynchronous function is useless but it's to show that I tried different ways to catch those exceptions but nothing works.

Your sintax is wrong:

try {
    $.ajax {
        async: false,
        type: "GET",
        url: index_url,
        success: function(data) {
            alert ("post is success");
        },
        error: function(request,error) { 
            alert(request.responseText);
            alert(error);
        }
    }
} catch (e) {
    console.log(e);
}

But as suggested, you can use the ajax response to do what you want depending the result...

When you make an ajax call with a bad url, the failure is written in the error function or fail function, you don't need a try catch for an ajax request because it doesn't throw any kind of errors at least in this case.

Stupid answer...

There was an missing space before my error method. Thanks for your help.