title: How to catch and ignore IncompatibleType Error in Java
body: <p>I have been searching for about 2 hours now and cannot find a way to catch and ignore an incompatible type error in Java. This is compile-time error caused by attempting to assign a float value to an integer. I know why this error is occurring (narrow conversion) and specifically WANT this error to occur as it is for a demonstration of the error itself (needed for a course I am in), but in attempting to catch the error using a try-catch statement I am having no luck.</p>
  
  <p>I know you should specify the error type you are catching, but for the purpose of this code it is okay if I take the generic route here, because everything is pretty well contained and very simple. I would never use this kind of error checking for anything more involved than the purposes of this project, but if you know the exact error type causing the message "error: incompatible types: possible lossy conversion from float to int" to be displayed when attempting to compile, I'll use that error type. I looked through multiple sites and could not find the exact type of this error (such as IOException, for example).</p>
  
  <p>Here is the code I am trying to execute: </p>
  
  <pre><code>import java.lang.*;
  public class AssignTests {  
  
  int integer = 10;
  float floater = 1234.1234f;
  
  public static void main(String[] args){ 
      AssignTests test = new AssignTests();
  
      try{
          test.integer = test.floater;
      }
      catch (Exception t)
      {
          System.out.println("An integer cannot be assigned the value of a float.");
      }
    }
  }
  </code></pre>
  
  <p>When I go to compile this code I still see the error message of incompatible types despite trying to ignore this issue via the try-catch statement, and after searching for this long on how to resolve this am pretty stumped.</p>
  
  <p>Any idea on how to get this to compile and give me the output message I am looking for?</p>