Bug 473762

Summary: Need a way to check exceptions in external DOM classes, in codeassist class ThrownExceptionFinder has method processThrownExceptions, but issues are it only takes TryStatement and it uses internal classes
Product: [Eclipse Project] JDT Reporter: Md Arefin <arefin.shahrear>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: raffi.khatchadourian
Version: 4.6   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Md Arefin CLA 2015-07-28 10:10:00 EDT
we would like to check that a block of code (e.g., a for loop body) does not throw checked exceptions. Note that, if a block of code does throw a checked exception, the code will compile so as long as the method header/signature has a throws clause. Here's an example:

void m() throws Exception {
    for (...) {
        throw new Exception(); //bad.
    }
    for (...) {
        //good.
    }
}

Note that this is not as simple as just checking for throw statements in the AST of the loop body as the body may call methods that throw exceptions and the throw could appear in a try/catch block that does not rethrow the exception.

there is a method org.eclipse.jdt.internal.codeassist.ThrownExceptionFinder.getThrownUncaughtExceptions()
It seems that the method to call first is ThrownExceptionFinder.processThrownExceptions(TryStatement, BlockScope) rather than TryStament we need to check for any kind of statement so that we can find exceptions in an arbitrary statement.
Comment 1 Md Arefin CLA 2015-07-28 10:26:08 EDT
Netbeans also has done similar work at  org.netbeans.api.java.source.TreeUtilities.getUncaughtExceptions() 

we think one solution might be not to use the internal compiler DOM classes 

The forum links are below for this issue:
https://dev.eclipse.org/mhonarc/lists//jdt-core-dev/msg02435.html
https://dev.eclipse.org/mhonarc/lists//jdt-core-dev/msg02446.html