title: How to handle exceptions: "ERROR] FATAL UNHANDLED EXCEPTION:"
body: <p>I created a class dubPrime that takes an integer that must be a double digit. If it isn't a double digit the program is supposed to throw an exception. However my program crashes and outputs &quot;[ERROR] FATAL UNHANDLED EXCEPTION&quot; whenever I try to create an object that is not a double digit.
  *I used the factory design pattern so that the object wouldn't be created if it doesn't meet the standards.</p>
  <p>Is there a way to circumvent this so that my program doesn't crash?</p>
  <pre><code>    private DubPrime(bool upArg, bool enabledArg, uint xArg){
          x = xArg;
          up = upArg;
          enabled = enabledArg;
      }
  
      public static DubPrime GetDubPrime(bool upArg = true, bool enabledArg = true, uint xArg = lowerLimit){
          //x must be double digit
          if(xArg&lt;lowerLimit || xArg&gt;upperLimit) 
              throw new ArgumentException(&quot;x should be a double digit&quot;);
          else{
              return new DubPrime(upArg, enabledArg, xArg);
          }
      
      }
  </code></pre>
  <p>Update: Whenever I try to add a try/catch block the compiler says &quot;not all code paths return a value.&quot; Is it necessary to return something? Could I throw an exception and not have it return something?</p>
  <pre><code>   public static DubPrime GetDubPrime(bool upArg = true, bool enabledArg = true, uint xArg = lowerLimit){
          try{
              if(xArg&lt;lowerLimit || xArg&gt;upperLimit) 
                  throw new ArgumentException(&quot;x should be a double digit&quot;);
              else{
                  return new DubPrime(upArg, enabledArg, xArg);
              }
          }
          catch(Exception e){
              Console.WriteLine(e.Message);
          }
      }
  </code></pre>