title: Returning object reference and Exception from method same time
body: <p>I just tried to implement Singleton pattern to WinForms ,so that only one instance of a form stays in the Application life ,but i face a difficulty </p>
  
  <p>I want to throw exception if the instance of singleton exists and return same instance reference at the same time.</p>
  
  <h1>SingletonForm.cs</h1>
  
  <pre><code>public class SingletonForm : BaseFormcs
  {
      private static SingletonForm _instance;
      //To stop new keyword from instantiation 
      private SingletonForm()
      { }
      public static SingletonForm GetInstance()
      {
          if (_instance == null)
              return _instance = new SingletonForm();
  
          else
          {
              throw new Exception("Form already exists"); // execution returns from here
              return _instance; // Warning : Unreachable code detected
              //I also want to return instance reference.
          }
  
      }
  }
  </code></pre>