mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bug 69744 - better error handling around catch blocks
This commit is contained in:
parent
610efadb58
commit
efc3b9c4ab
2 changed files with 38 additions and 8 deletions
|
@ -10,8 +10,12 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
/**
|
||||
|
@ -91,4 +95,24 @@ public class CompleteParseProblemTest extends CompleteParseBaseTest {
|
|||
assertEquals( p.getSourceEnd(), end );
|
||||
assertEquals( p.getID(), IProblem.SEMANTIC_NAME_NOT_FOUND );
|
||||
}
|
||||
|
||||
public void testBug69744() throws Exception
|
||||
{
|
||||
String code = "int f() { try { } catch( foo bar ) {} catch ( ... ) {} } int i;"; //$NON-NLS-1$
|
||||
|
||||
Iterator i = parse( code, false ).getDeclarations();
|
||||
|
||||
int start = code.indexOf( "foo" ); //$NON-NLS-1$
|
||||
int end = start + 3;
|
||||
|
||||
assertEquals( callback.problems.size(), 1 );
|
||||
IProblem p = (IProblem) callback.problems.get( 0 );
|
||||
|
||||
assertEquals( p.getSourceStart(), start );
|
||||
assertEquals( p.getSourceEnd(), end );
|
||||
assertEquals( p.getID(), IProblem.SEMANTIC_NAME_NOT_FOUND );
|
||||
|
||||
IASTFunction f = (IASTFunction) i.next();
|
||||
IASTVariable varI = (IASTVariable) i.next();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3150,15 +3150,21 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
while (LT(1) == IToken.t_catch) {
|
||||
consume(IToken.t_catch);
|
||||
consume(IToken.tLPAREN);
|
||||
if (LT(1) == IToken.tELLIPSIS)
|
||||
consume(IToken.tELLIPSIS);
|
||||
else
|
||||
simpleDeclaration(SimpleDeclarationStrategy.TRY_VARIABLE,
|
||||
scope, null, CompletionKind.EXCEPTION_REFERENCE, true,
|
||||
KeywordSetKey.DECL_SPECIFIER_SEQUENCE);
|
||||
consume(IToken.tRPAREN);
|
||||
|
||||
catchBlockCompoundStatement(scope);
|
||||
try {
|
||||
if (LT(1) == IToken.tELLIPSIS)
|
||||
consume(IToken.tELLIPSIS);
|
||||
else
|
||||
simpleDeclaration(SimpleDeclarationStrategy.TRY_VARIABLE,
|
||||
scope, null, CompletionKind.EXCEPTION_REFERENCE, true,
|
||||
KeywordSetKey.DECL_SPECIFIER_SEQUENCE);
|
||||
consume(IToken.tRPAREN);
|
||||
|
||||
catchBlockCompoundStatement(scope);
|
||||
} catch (BacktrackException b) {
|
||||
failParse(b);
|
||||
failParseWithErrorHandling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue