Bug 45064 - Unused throws declaration
Summary: Unused throws declaration
Status: CLOSED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-16 18:41 EDT by Vijay Aravamudhan CLA
Modified: 2004-06-23 12:30 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vijay Aravamudhan CLA 2003-10-16 18:41:54 EDT
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?
Comment 1 Adam Kiezun CLA 2003-10-16 19:11:04 EDT
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?
Comment 2 Vijay Aravamudhan CLA 2003-10-16 19:14:07 EDT
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?
Comment 3 Adam Kiezun CLA 2003-10-16 19:17:21 EDT
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.
Comment 4 Adam Kiezun CLA 2003-10-16 19:22:13 EDT
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. :-)
Comment 5 Vijay Aravamudhan CLA 2003-10-16 19:36:02 EDT
ok - i can accept that argument!
Comment 6 Vijay Aravamudhan CLA 2004-06-23 12:30:27 EDT
Verified that my use case was incorrect.
Comment 7 Vijay Aravamudhan CLA 2004-06-23 12:30:43 EDT
Closing.