title: how to return exception to AJAX call from webmethod?
body: <p>I am returning <code>List&lt;strings&gt;</code> from <code>[WebMethod]</code>. But when exception occurs how to return <code>failure</code> message to AJAX caller?. Now I am getting build error.</p>
  
  <p>JS:      </p>
  
  <pre><code>$.ajax({
      type: 'POST',
      contentType: "application/json; charset=utf-8",
      url: 'new.aspx/GetPrevious',
      data: "{'name':'" + username + "'}",
      async: false,
      success: function (data) {
          Previous = data.d;
          alert(salts);
      },
      error: function () {
          alert("Error");
      }
  });
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>[WebMethod]
  public static List&lt;string&gt; GetPreviousSaltsAndHashes(string name)
  {
      try
      {
          List&lt;string&gt; prevSalts = new List&lt;string&gt;();
          if (reader.HasRows)
          {
              while (reader.Read())
              {                      
                  prevSalts.Add(reader.GetString(0));
              }
          }
          conn.Close();
          return prevSalts;
      }
      catch (Exception ex)
      {
          return "failure"; //error showing here
      }
  }
  </code></pre>