• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

method throws exception is NOT inside a try/catch block. jbuilder does not show error

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a class called DataClient that calls the constructor of another class called Data in its constructor. The constructor of Data throws an IOException.
When I compile these two classes in JBuilder 6 or 7 they generate no errors even though the constructor of Data is not inside a try/catch block and the constructor of DataClient does not throw an exception.
It's weird because if I copy the call to the constructor of Data to another method inside DataClient class, I get an error at compile time asking me to either put this call in a try/catch block or declare that the method throws an exception.
is this a bug?
can anyone help me out?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please post the relevant code? That would make discussing it much easier...
 
Leonardo Penha
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Here it goes:
file #1:
public class Data {
public Data(String dbname) throws IOException {
...
}
...
}
file #2:
public class DataClient {
private Data data;
public DataClient(String dbName) {
data = new Data(dbName);
...
}
...
public void close() throws RemoteException {
data.close();
}
}
---------------------------------------
The above code does not compile with jdk1.4 because Data constructor throws IOException,
but DataClient's constructor doesn't.
However, when I use JBuilder, it does!
The weird thing is that if I copy the first line on DataClient's constructor to the method close() of the DataClient class the code does not compile.
 
Leonardo Penha
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry. I think the code above will not compile. But if you add another constructor to DataClient (one that takes another kind of argument, of course) that throws an IOException, then it will compile, even though it shouldn't.
 
Leonardo Penha
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's definetely a bug!
try this:
file #1:
package applications;
import java.io.IOException;
public class ExceptionThrower {
public ExceptionThrower() throws IOException {}
}
file #2:
package applications;
import java.io.IOException;
public class ExceptionTest {
public ExceptionTest() {
new ExceptionThrower();
}
public ExceptionTest(String s) throws IOException {}
public static void main(String[] args) {
new ExceptionTest();
}
}
Try compiling both files, first from within JBuilder, then from the command line with the javac tool.
Then try commenting the second constructor on the file #2 and compiling both file again.
you'll see what I mean.
:-)
 
Do you pee on your compost? Does this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic