History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEA-11677
Type: Bug Bug
Status: Open Open
Assignee: Alexey Kudravtsev
Reporter: Esko Luontola
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Feedback

Automatically generated catch block uses an unnecessarily long variable name for the exception, when its class name does not end with "Exception"

Created: 22 Feb 07 18:59   Updated: 26 Feb 07 11:53
Component/s: Editor. Code Completion, Editor. Intention Actions

Build: 6,148


 Description  « Hide
In the following code, if you use the "surround with try/catch" quickfix in the main method...
public class ExceptionTest {

    public static void main(String[] args) {
        throw new ExceptionIsNotTheLastWord();
    }
}

class ExceptionIsNotTheLastWord extends Exception {

}

...the resulting code will be like this:

public class ExceptionTest {

    public static void main(String[] args) {
        try {
            throw new ExceptionIsNotTheLastWord();
        } catch (ExceptionIsNotTheLastWord exceptionIsNotTheLastWord) {
            exceptionIsNotTheLastWord.printStackTrace();
        }
    }
}

class ExceptionIsNotTheLastWord extends Exception {

}

IDEA generates a short name for the exception only, when the exception's class name ends with "Exception". This also affects catching the Throwable class - IDEA will generate "catch (Throwable throwable)" even though it would look better as "catch (Throwable t)".

EXPECTED

  • For Throwable, use "t" as the variable name. For all other exceptions, use "e" as the variable name. (I think this would be the best method, what the programmer would except.)
    OR
  • When creating a catch statement, use the first letter of the last word in the exception's class name as the variable name for the exception.


 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.