{
ExceptionHandlers handlers= new ExceptionHandlers(code);
Iterator<ExceptionHandler> handleIterator= handlers.iterator();
ExceptionHandler handle= handleIterator.hasNext() ? handleIterator.next() : null;
while (handle != null)
{
boolean hasFinally= false;
int start= handle.getStartPC();
int end= handle.getEndPC();
TryStatement tryStmt= new TryStatement();
tryStmt.header= (TryHeaderNode) graph.createNode(TryHeaderNode.class);
tryStmt.header.tryStmt= tryStmt;
Block tryBlock= new Block(start, end);
tryStmt.setTryBlock(tryBlock);
// tryStmt.setBeginIndex(start);
tryStatements.add(tryStmt);
CatchClause cStmt= null;
// Collect all non-default handlers. The range of each handler is
// from the 'store'-instruction to the beginning of the next
// handler.
while (handle != null && !handle.isDefault() && handle.getStartPC() == start && handle.getEndPC() == end)
{
if (cStmt != null)
{
cStmt.setEndIndex(handle.getHandlerPC() - 1);
}
cStmt= createCatchClause(tryStmt, handle);
handle= handleIterator.hasNext() ? handleIterator.next() : null;
}
int foo= -1;
if (handle != null && handle.isDefault() && handle.getStartPC() == start)
{
// Collect first default handler.
hasFinally= true;
if (cStmt != null)
{
cStmt.setEndIndex(handle.getHandlerPC() - 1);
tryStmt.setEndIndex(handle.getHandlerPC() - 1);
// Warning: We only set a lower bound for the end index. The
// correct index is set later
// when the finally statement is analysed.
}
cStmt= createCatchClause(tryStmt, handle);
foo= handle.getHandlerPC();
handle= handleIterator.hasNext() ? handleIterator.next() : null;
}
// Last catch stmt has no endIndex, yet!
while (handle != null && handle.isDefault() && (handle.getHandlerPC() == foo))
{
// Skip all remaining default handlers.
throw new RuntimeException("remaining default handlers");
// handle = handleIterator.hasNext()?handleIterator.next():null;
}