title: Catch ArgumentException on WebService when receive Null Parameters
body: <p>Ok so yesterday I posted some problem I had with some system I'm developing. The problem I have now here, I am going through the worst case scenario and thinking that the user somehow tries to call my web service and forgets to put in the parameters, therefore the web service receives null parameters ... I tried validating with <code>If</code>, and still it threw me an <code>ArgumentException</code> error, so I left the took off the <code>if</code> validation and instead I placed the whole code in a <code>try-catch</code>, the problem is that this "catch does not go into that code block, it just keeps throwing the <code>ArgumentException</code> on plain web text ... </p>
  
  <p>Here is my code:</p>
  
  <pre><code>[WebMethod(Description = "Private Title", EnableSession = false)]
  public string[] M102(int p_enclosure, string p_transaction, int p_operation, int p_commodity,
                            string p_bl, string p_inDate, string p_blhouse, string p_anexo29, int p_tranType,
                            string p_vessel, string p_trip, int p_entry, string p_padlock, string p_brands, 
                            string p_appoint, string p_plates, string p_qmark)
  {
      string eDate;
      try
      {/*/WebService Code/*/}
      catch (ArgumentException Ex)
      {
          string message;
          string[] error = 
              { 
                  "000",
                  "DataCaptureError.- " + Ex.Message,
                  "Date"
              };
          SqlConnection con8 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CTSSQL"].ConnectionString);
          SqlCommand cmd8 = new SqlCommand();
          cmd8.Connection = con8;
          cmd8.CommandText = "dbo.sp_errorlog";
          cmd8.CommandType = CommandType.StoredProcedure;
          cmd8.Parameters.Add("@p_inTrans", SqlDbType.NChar, 12).Value = "0";
          cmd8.Parameters.Add("@p_enclosure", SqlDbType.NChar, 6).Value = "0";
          cmd8.Parameters.Add("@p_trans", SqlDbType.NChar, 18).Value = "0";
          cmd8.Parameters.Add("@p_method", SqlDbType.NChar, 6).Value = "102";
          cmd8.Parameters.Add("@p_message", SqlDbType.NVarChar, 250).Value = error[1];
          cmd8.Parameters.Add("@vo_message", SqlDbType.VarChar, 250).Direction = ParameterDirection.Output;
          cmd8.Parameters.Add("@vo_errorDate", SqlDbType.DateTime).Direction = ParameterDirection.Output;
          con8.Open();
          cmd8.ExecuteNonQuery();
          con8.Close();
          cmd8.Connection.Close();
          message = "" + cmd8.Parameters["@vo_message"].Value;
          eDate = "" + cmd8.Parameters["@vo_errorDate"].Value;
          eDate = Convert.ToDateTime(eDate).ToString("dd/MM/yyyy HH:mm:ss");
          error[2] = eDate;
          return error;
      }
  
  }
  </code></pre>
  
  <p>What I'm trying to do is to get that error message and put it in a my DB ... The thing is that it never enters in the CATCH code, it goes straight and spit out the error.</p>
  
  <p>Hope somebody can help me find a way to catch or validate this NULL parameter issue and stick it in the DB</p>
  
  <p>Thanks anyways guys.</p>