New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new Check: ForbidThrowAnonymousExceptions #117

Closed
romani opened this Issue Jun 27, 2013 · 3 comments

Comments

Projects
None yet
4 participants
@romani
Member

romani commented Jun 27, 2013

Description and discussion of the problem: http://stackoverflow.com/questions/17334498/throw-anonymous-exceptions-in-java

Task: create new Check that catch that situation, add option to create list of ignored Exceptions to instantiate (there could be a lot of legacy code, and some time it could be very useful - but it is more exception than rule).

Forbid throwing anonymous exception. limitation: This Check does not validate cases then Exception object is created before it is thrown.

For example:

catch (Exception e) {
   throw new RuntimeException() { //anonymous exception
    //some code
   };

@ghost ghost assigned miraxes Jul 17, 2013

@isopov

This comment has been minimized.

Show comment
Hide comment
@isopov

isopov Jul 23, 2013

Member

With Checkstyle it is not possible to check the case when anonymous exception is created in one source file and thrown in the other. However during exception creation it is also not possible to know whether this anonymous class is exception or not. So this check inside Checkstyle will miss some cases.

I think it is another idea that is worth adding to some other tooling capable of operating on class-files and reading the whole inheritance chain.

Member

isopov commented Jul 23, 2013

With Checkstyle it is not possible to check the case when anonymous exception is created in one source file and thrown in the other. However during exception creation it is also not possible to know whether this anonymous class is exception or not. So this check inside Checkstyle will miss some cases.

I think it is another idea that is worth adding to some other tooling capable of operating on class-files and reading the whole inheritance chain.

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jul 24, 2013

Member

It is clear that checkstyle will not be able cover all cases - and will not be part of main Checkstyle project.
One more case: anonymous exception is created by numerous calls of methods to create it.
Exception class detection could be done if creation is same catch block by detecting "Exception" at the end of class name - this will cover 95% of cases.

Member

romani commented Jul 24, 2013

It is clear that checkstyle will not be able cover all cases - and will not be part of main Checkstyle project.
One more case: anonymous exception is created by numerous calls of methods to create it.
Exception class detection could be done if creation is same catch block by detecting "Exception" at the end of class name - this will cover 95% of cases.

maxvetrenko added a commit to maxvetrenko/sevntu.checkstyle that referenced this issue Apr 10, 2014

maxvetrenko added a commit to maxvetrenko/sevntu.checkstyle that referenced this issue Apr 10, 2014

@romani romani closed this in 4ea10c1 Apr 10, 2014

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Apr 10, 2014

Member

Current Check implementation limitation will be resolved at #183

Member

romani commented Apr 10, 2014

Current Check implementation limitation will be resolved at #183

@romani romani reopened this Apr 10, 2014

@romani romani closed this Apr 10, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment