title: How to handle management exception for WMI
body: <p>i am reading processor's details <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394373%28v=vs.85%29.aspx" rel="nofollow">WIN32_PROCESSOR</a> using WMI. Currently i am trying to read these property:<code>SELECT CAPTION,L2CACHESIZE,L3CACHESIZE FROM WIN32_PROCESSOR</code>. So that i am working with below code:</p>
  
  <pre><code>static void Main(string[] args)
  {
      string strQuery = "SELECT CAPTION,L2CACHESIZE,L3CACHESIZE FROM WIN32_PROCESSOR";
      string strIPAddress = "XXX.XXX.X.XXX";
      DataTable dtProcessor = new DataTable();
      dtProcessor.Columns.Add("CAPTION");
      dtProcessor.Columns.Add("L2CACHESIZE");
      dtProcessor.Columns.Add("L3CACHESIZE");            
  
      ManagementScope scope = new ManagementScope(@"\\" + strIPAddress + @"\root\cimv2");
      SelectQuery query = new SelectQuery();
      query.QueryString = strQuery;
      ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
      ManagementObjectCollection queryCollection = searcher.Get();
      foreach (ManagementObject mngmntObj in queryCollection)
      {
          DataRow dr = dtProcessor.NewRow();
          dr["CAPTION"] = mngmntObj["CAPTION"];
          dr["L2CACHESIZE"] = mngmntObj["L2CACHESIZE"];
          dr["L3CACHESIZE"] = mngmntObj["L3CACHESIZE"];
          dtProcessor.Rows.Add(dr);
  
      }
  }
  </code></pre>
  
  <p>This is working fine on my Windows Server 2008R2 machine, but the same code giving me exception of <code>System.Management.ManagementException</code> -> <code>Invalid Query</code> because <code>L3CACHESIZE</code> is not present in XP as discussed <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394373%28v=vs.85%29.aspx" rel="nofollow">here</a>. 
  What can be best way to handle this with reading values which are present ?</p>