(Answer) (Category) FAQ-O-Matic : (Category) JBuilder 4 Known Bugs :
Unreported Exception error message in an anonymous class
Summary: When JBuilder compiles an anonymous class, it is required to provide
default anonymous constructors.  However, some anonymous classes can throw
exceptions in the constructors and so these must be declared by the compiler.
JBuilder fails to provide the throws clause, thus causing the error message.  

Because one isn't allowed to define an explicit constructor for an anonymous
class, the workaround is to convert the anonymous class into a named inner
class and explicitly declare the constructor and its throws clause there.


Example code from Vito:


Here follows a more straightforward TestClass that reproduces the bug,
followed by a TestClass2 that compiles correctly with JBuilder4:

----------TestClass
compilin with JBuilder 4 gives error "TestClass.java": Error #: 360 :
unreported exception: java.io.FileNotFoundException; must be caught or
declared to be thrown at line 15, column 43,
while compiles correctly with javac:

package test;
import java.io.*;

public class TestClass {

  public TestClass() {
   try {
     instantiateAndClose();
   }
   catch (Exception x) {
   }
  }

  public void instantiateAndClose() throws Exception{
   FileInputStream fi=new FileInputStream("testfile"){
     protected void finalize() throws IOException {
     }
   };
   fi.close();
  }
}
-----------------------------
Follows TestClass2, where I declare the class MyFileInputStream with the
correct constructor, that compiles correctly with JBuilder4:

---------TestClass2
package test;
import java.io.*;

public class TestClass2 {

  class MyFileInputStream extends FileInputStream {
   public MyFileInputStream(String name) throws FileNotFoundException {
     super(name);
   }
   protected void finalize() throws IOException {
   }
  }
  public TestClass2() {
   try {
     instantiateAndClose();
   }
   catch (Exception x) {

   }
  }

  public void instantiateAndClose() throws Exception{
   FileInputStream fi=new MyFileInputStream("testfile");
   fi.close();
  }
}
---------------
Vito.
2001-Feb-12 9:59pm gyles19@visi.com
[Append to This Answer]
2001-Feb-12 9:59pm
Previous: (Answer) Compiler Error: "Error #: 2301 : internal compiler error: java.lang.NullPointerException"
Next: (Answer) UNVERIFIED: Jbuilder accepts assignments to 'final' variables.
This document is: http://www.visi.com/~gyles19/cgi-bin/fom.cgi?file=86
[Search] [Appearance]
This is a Faq-O-Matic 2.709.
This FAQ administered by gyles19@visi.com.

Other JBuilder Links

Java Community
Java Tools
Code Central
JB OpenTools
Community
Recent
Threads
Borland Chat
Chat FAQ
Feature Matrices
3.0 |  3.5 |  4.0
5.0 |  6.0 |  7.0
Shop for
JBuilder
JBuilder
Downloads
and reg keys
Report Piracy
Online Manuals
4.0 |  5.0 |  6.0
7.0
Borland
DevSupport's
Bug/RFE Form

Quality Central Client
JB Patches &
Updates
JBuilder FAQs TIs
JBuilder
Newsgroups
Tamaracka's
News Archive
Mr. Haki's
JBuilder Machine
JGuru's
JBuilder FAQ
Sun's Bug
Parade
Netring Home - About - Privacy
The
JBuilder Netring Logo
The Borland JBuilder Netring by JBuilder FAQ-O-Matic
[ Join Now | List Sites | Random | << Prev | Next >> ]
[ Previous 5 Sites | Skip Previous | Skip Next | Next 5 Sites ]