title: C#: Throwing Custom Exception Best Practices
body: <p>I have read a few of the other questions regarding C# Exception Handling Practices but none seem to ask what I am looking for.</p>
  
  <p>If I implement my own custom Exception for a particular class or set of classes. Should all errors that relate to those classes be encapsulated into my exception using inner exception or should I let them fall through?</p>
  
  <p>I was thinking it would be better to catch all exceptions so that the exception can be immediately recognized from my source. I am still passing the original exception as an inner exception. On the other hand, I was thinking it would be redundant to rethrow the exception.</p>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>class FooException : Exception
  {
      //...
  }
  </code></pre>
  
  <p><strong>Option 1: Foo encasulates all Exceptions:</strong></p>
  
  <pre><code>class Foo
  {
      DoSomething(int param)
      {
          try 
          {
               if (/*Something Bad*/)
               {  
                   //violates business logic etc... 
                   throw new FooException("Reason...");
               }
               //... 
               //something that might throw an exception
          }
          catch (FooException ex)
          {
               throw;
          }
          catch (Exception ex)
          {
               throw new FooException("Inner Exception", ex);
          }
      }
  }
  </code></pre>
  
  <p><strong>Option 2: Foo throws specific FooExceptions but allows other Exceptions to fall through:</strong></p>
  
  <pre><code>class Foo
  {
      DoSomething(int param)
      {
          if  (/*Something Bad*/)
          {
               //violates business logic etc... 
               throw new FooException("Reason...");
          }
          //... 
          //something that might throw an exception and not caught
      }
  }
  </code></pre>