title: VBScript error handling in C#
body: <p>I want to access WMI using the <code>AutomationFactory</code> in a Silverlight OOB application.</p>
  
  <pre><code>dynamic locator = AutomationFactory.CreateObject("WbemScripting.SWbemLocator");
  dynamic wmi = locator.ConnectServer(".", "\\root\\cimv2");
  </code></pre>
  
  <p>I now want to add error handling to this.</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa393720%28v=vs.85%29.aspx" rel="nofollow">MSDN</a> states that the return value is a reference to the connected object if the call is successful and that in case of an error I should check the <code>Err</code> object. However, there are two questions I have with this:</p>
  
  <ul>
  <li>What is the return value if the call is not successful? null? Some arbitrary pointer that I cannot use?</li>
  <li>How can I access the <code>Err</code> object in Silverlight?</li>
  <li>How can I detect if the call was successful? May there be any exceptions which I have to catch?</li>
  <li>I've seen some examples using the <code>using</code> statement, and some without. Do I have to dispose the dynamic objects manually after I've used them?</li>
  </ul>