IntelliJ IDEA: Exception removal will break source code. Proceed anyway?

Ruby :

I have a method that throws a deprecated exception, which I've removed all cases where this exception is thrown. I tried to use IntelliJ IDEA's "Remove from throws list" refactor action to remove it, and got the following error,

Refactoring Error dialog

What does it mean?

I searched for this on DuckDuckGo and Google, but the only relevant result I could find was IntelliJ IDEA's source code.

Stanley F. :

I don't know the library you are using or how ConditionParseException is implemented. However, it seems to be a so called checked exception.

A checked exception cannot be ignored, you have to somehow handle the case of an exception being thrown. This can be done either by catching it or by delegating it up to the caller of the method. In your current implementation, the latter one is done by adding the exception type to the list of throws.

If you want to remove the exception from the throws declaration, you have to handle it using a try-catch block, e.g.:

try {

} catch (ConditionParseException ex) {

}

Another possibility would be to make it an unchecked exception. For this, handling an exception it is not mandatory. For a detailed explanation of both kinds of exception, let me refer to this question.

TL;DR

However, if you want to completely get rid of the ConditionParseException type (since it is deprecated), you have to:

  • click "yes" in the "Cannot perform refactoring" dialog
  • remove every other use of ConditionParseException. (e.g. catch blocks and throw new ConditionParseException statements)
  • remove the ConditionParseException java file.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=105136&siteId=1