title: NotFound cannot be converted to Throwable
body: <p>I want to achieve one objective. I am sharing my concept with demo code.</p>
  
  <pre><code>interface NotFound{
          //define one marker interface which will mark not found  
      }
  
  class ServiceException extends RuntimeException{
  
  }
  
  class TeacherServiceException extends ServiceException{
  
  }
  
  
  class TeacherNotFoundException extends TeacherServiceException
  implements NotFound{
      TeacherNotFoundException(){
      //if teacher is null then will throw this type of exception
     }
  }
  
  
  class StudentServiceException extends ServiceException{
  
  }
  
  
  class StudentNotFoundException extends StudentServiceException
  implements NotFound{
      StudentNotFoundException(){
      //if student is null then will throw this type of exception
     }
  }
  
  
  interface HasName{
      void addName(String name);
  } 
  
  
  //these are the models
  class Student implements HasName{
  
      @Override
      public void addName(String name){
  
  
      }
  
  }
  
  
  class Teacher implements HasName{
      @Override
      public void addName(String name){
  
      }
  }
  
  //these are the resources 
  
  
  class StudentResource{
  
      StudentService service = new StudentService(null);
  
      NameSupportResource&lt;TeacherService&gt; support = new NameSupportResource&lt;&gt;();
  
      void addName(String name){
  
          support.addName(service,name);
      }
  
  }
  
  class TeacherResource{
  
      TeacherService service = new TeacherService(null);
  
      NameSupportResource&lt;TeacherService&gt; support = new NameSupportResource&lt;&gt;();
  
      void addName(String name){
  
          support.addName(service,name);
  
      }
  }
  
  class NameSupportResource&lt;T extends HasNameService&gt;{
  
      void addName(T service,String name){
  
          try{
              service.addName(name);
          }
          catch(NotFound e){
  
          }
  
      }
  }
  
  //these are the services
  
  interface HasNameService&lt;T extends HasName&gt;{
  
      T addName(String name);
  }
  
  class StudentService implements HasNameService&lt;Student&gt;{
  
      Student student;
  
      StudentService(Student student){
  
          this.student = student;
      }
  
      @Override
  
      public Student addName(String name){
  
          if(student ==  null)
              throw new StudentNotFoundException();
          else{
  
              student.addName(name);
  
              return student; 
          }
  
      }
  
  }
  
  
  class TeacherService implements HasNameService&lt;Teacher&gt;{
  
      Teacher teacher;
  
      TeacherService(Teacher teacher){
  
          this.teacher = teacher;
      }
  
      @Override
      public Teacher addName(String name){
  
          if(teacher ==  null)
              throw new TeacherNotFoundException();
          else{
  
              teacher.addName(name);
  
              return teacher;
          }
  
      }
  
  }
  </code></pre>
  
  <p>Here you can see that if studnet is null or teacher is null then it can throw <code>StudentNotFoundException</code> or <code>TeacherNotFoundException</code> respectively.</p>
  
  <p>The purpose of using <code>NameSupportResource</code> is to make common. because in future i can introduce another model like <code>Student</code> or <code>Teacher</code> they can have same name add operation. Now if any model is null i want to throw sub type exception i.e. <code>StudentNotFoundException</code>. Let say i want to introduce another model i.e. book, and if book is null then i will throw <code>BookNotFoundException</code>. But i want to catch it by parent type. That is why i have defined maker interface. As we know an interface can point to class object.</p>
  
  <p>But i have seen one error </p>
  
  <pre><code>incompatible types: NotFound cannot be converted to Throwable
          catch(NotFound e){
                ^
  1 error
  </code></pre>
  
  <p>Can you tell me how i can solve it??</p>