protected CodeBlock getRethrowExpectedExceptions() {
// first build up a list of the exceptions that should be handled.
final Method method = this.getMethod();
final GeneratorContext context = method.getGeneratorContext();
final List<Type> alreadyCaughts = new ArrayList<Type>();
final Type exception = context.getType(Constants.EXCEPTION);
final Type runtimeException = context.getType(Constants.RUNTIME_EXCEPTION);
final List<Type> catchAndRethrow = new ArrayList<Type>();
final Iterator<Type> thrown = this.getMethod().getThrownTypes().iterator();
while (thrown.hasNext()) {
final Type expected = thrown.next();
if (expected.isAssignableTo(runtimeException)) {
continue;
}
if (false == expected.isAssignableTo(exception)) {
continue;
}
boolean dontCatch = false;
final Iterator<Type> alreadyCaughtsIterator = alreadyCaughts.iterator();
while (alreadyCaughtsIterator.hasNext()) {
final Type alreadyCaught = (Type) alreadyCaughtsIterator.next();
if (expected.isAssignableTo(alreadyCaught)) {
dontCatch = true;
break;
}
}