title: How to create a custom C# exception?
body: <p>I'm currently learning C#, but I am stuck on something and I can't find a solution for it.<br>
  I am trying to create my own Exception class. </p>
  
  <p>The exception is called "InvalidNumberException", it checks if a number is equal to 5. I know it may seem kinda stupid, but I just need to get the idea about creating Custom Exceptions. </p>
  
  <p>So far I found on MSDN that for creating the Exception I need these four constructors:</p>
  
  <pre><code>public class InvalidNumberException : System.Exception
  {
      public InvalidNumbertException() : base() { }
      public InvalidNumberException(string message) : base(message) { }
      public InvalidNumberException(string message, System.Exception inner) : base(message, inner) { }
  
      // A constructor is needed for serialization when an
      // exception propagates from a remoting server to the client. 
      protected InvalidNumberException(System.Runtime.Serialization.SerializationInfo info,
          System.Runtime.Serialization.StreamingContext context) { }
  }
  </code></pre>
  
  <p>but I don't know how to implement the method or constructor in this class that a number entered from the console is equal to 5, and if it is not, it throws an exception.</p>
  
  <p>I'll appreciate if someone helps me with this. </p>