title: Handling exceptions with interfaces and classes in java
body: <p>So picture the following scenario. I have two sets of classes and interfaces. <code>ClassA</code>, <code>ClassB</code>, <code>ClassAInterface</code>, and <code>ClassBInterface</code>. <code>ClassA</code> uses <code>ClassB</code> in several of its methods. These methods from ClassB occasionally throw exceptions.</p>
  
  <pre><code>public class ClassA implements ClassAInterface {
     public void example() {
        ClassB test = new ClassB();
        ClassB.exampleTest();
  
        //more code using ClassB 
     }
  }
  
  public class ClassB implements ClassBInterface {
     public void exampleTest() throws ExampleException() {
        boolean tru = false;
        if (tru) {
           throw new ExampleException();
        }
     }
  }
  </code></pre>
  
  <p>So the problem that I'm having is that I'm getting an <code>Unhandled Exception type ExampleException()</code> error in the <code>ClassA.example()</code> method. Why does this happen? I want the <code>ClassB</code> method to throw the exception in specific cases, and signify that it sometimes throws exceptions with <code>throws ExampleException()</code>, so why does ClassA not compile. To solve it, I can't add a throws statement onto <code>ClassA.example()</code> because it would violate <code>ClassAInterface</code>. And if I just wrap <code>ClassB.exampleTest()</code> in a try catch statement, much of the rest of <code>ClassA.example()</code> would throw errors because <code>ClassB</code> signifies something is wrong and you should throw an exception at that point, which is the entire point of throwing an exception`. So I'm not sure why this is happening or how to solve it.</p>