Community
Participate
Working Groups
In my project, we use a lot of interfaces and factories to get to concrete implementations. If one of the implementations throws an Exception that another does not, we still need to declare it in the interface definition. If I turn on this check in the java compiler options, Eclipse reports tasks on those implementations that dont actually throw the exception. This makes the check unusable. I am using Eclipse 3.0 M4 on a windows XP machine. Could you please rectify?
do i understand correctly: you have interface I{ void doFoo() throws IOException; } class A implements I{ public void doFoo() throws IOException{ ... throw new IOException(); } } class B implements I{ public void doFoo() throws IOException{ //do not throw exception } } and the compiler complains. please note that you can _remove_ declared exceptions in classes implementing I, so this is OK: class B implements I{ public void doFoo(){ //do not throw exception } } or do i misunderstand your concern?
Yes - that is the case. But as i understand it, removing the declaration from the implementing class is not a good coding practice. OR am I wrong?
why should it be a bad practice? - i think it's a good practice. if the code does not throw an exception, don't declare it. otherwise you clients will have to handle it.
that is, you clients will have to write code to 'handle' exceptions that never occurr. thus, they will have to write dead code. that's 'bad coding practice' from where i'm sitting. :-)
ok - i can accept that argument!
Verified that my use case was incorrect.
Closing.