Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 438742

Summary: Throws declaration not enforced anymore?
Product: [Eclipse Project] JDT Reporter: J.F.Lanting <J.F.Lanting>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, Olivier_Thomann
Version: 4.4   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description J.F.Lanting CLA 2014-07-02 10:45:51 EDT
Hello,
I could be wrong, but it seems to me that the compiler (1.7) no longer forces me
to add a throws declaration to the method,
when I add a statement or method that throws.
Is this a bug or should I correct a compiler setting?
Thanks anyway.
;JOOP!
Comment 1 Jay Arthanareeswaran CLA 2014-07-02 10:58:06 EDT
Can you give me an example where you find this problem?
Comment 2 J.F.Lanting CLA 2014-07-02 11:19:06 EDT
This method may show:

   /**
    * Message can not delete/recycle/trash argument file.
    *
    * @param f file to be deleted.
    * @param operation text for the failure message.
    */
   static void cantDeleteFile(File f, String operation)
   {
      String type = f.isDirectory() ? "DIRECTORY:" : "FILE:";
      Object[] options = { "Continue", "Stop" };
      int answer;

      To.warning();
      answer = JOptionPane.showOptionDialog
      (
         Ui.getMainFrame(),
         "<HTML>"
            + "<CENTER>FAILED TO "
            + operation
            + type
            + "</CENTER><CENTER><STRONG STYLE=COLOR:BLUE>"
            + f.getAbsolutePath()
            + "</STRONG></CENTER>",
         "FAILURE",
         JOptionPane.YES_NO_OPTION,
         JOptionPane.WARNING_MESSAGE,
         null,
         options,
         options[0]
      );
      if(answer == 1)
      {
         throw new CancelledKeyException();
      }
   }

Of course only the last lines are of interest.
Thanks for your quick response.
;JOOP!
Comment 3 Olivier Thomann CLA 2014-07-02 11:22:06 EDT
CancelledKeyException is a runtime exception (unchecked exception). There is no need to add it into the throws clause of the method. Replace it with a checked exception (not under the RuntimeException) and it will work as expected.
Comment 4 J.F.Lanting CLA 2014-07-02 11:38:58 EDT
Apparently I'm not an expert.
The thing is: it works.
So you may close and I stop worrying.
;JOOP!