title: C# PowerPoint VSTO: Check if Any Slide is in View
body: <p>PowerPoint's interop library exposes <code>Globals.ThisAddIn.Application.ActiveWindow.View.Slide</code> which allows you to test if a slide (any Slide or Master) is currently selected and in the view.</p>
  
  <p>If no slide is currently in the view, then the <code>View</code> property is <code>null</code>. But here's the twist: you are unable to check <code>ActiveWindow.View</code> for null, without raising an exception.</p>
  
  <h3>My question is this:</h3>
  
  <p>How do you check if a slide/master is currently selected without resorting to an ugly try/catch like the following?</p>
  
  <pre><code>    internal static bool SlideActive =&gt; Slide != null;
  
      internal static dynamic Slide
      {
          get
          {
              try
              {
                  return Globals.ThisAddIn.Application.ActiveWindow.View.Slide;
              }
              catch
              {
                  return null;
              }
          }
      }
  </code></pre>
  
  <h3>EDIT:</h3>
  
  <p>This is the exception thrown when accessing <code>Slide</code> if none is in view:</p>
  
  <pre><code>{System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; 
  System.Runtime.InteropServices.COMException: View.Slide : Invalid request.  No slide is currently in view.
  </code></pre>