title: Java defining custom exceptions inside of class, is this bad?
body: <p>I have a class that has a method.  The method may fail and I want to throw an exception.  Is it bad to define the exception class within the namespace of the class whose function is throwing the exception?  I haven't seen a lot of examples of this, but it seems like the "right" (i.e. OO) way to do it?  Is there a reason I should avoid this pattern and define each custom exception in its own file?</p>
  
  <pre><code>public class Foo
  {
      void bar() {
          // do something and throw BarException if something bad happens
      }
  
      public static class BarException extends Exception {
          // rest of class definition
      }
  }
  </code></pre>