Class TryCatchFinallyStatementTransformer


public class TryCatchFinallyStatementTransformer extends AbstractStatementTransformer<TryCatchFinallyStatement>
  • Constructor Details

  • Method Details

    • compile

    • compile_impl

      protected IRStatement compile_impl()
      Specified by:
      compile_impl in class AbstractStatementTransformer<TryCatchFinallyStatement>
    • compileCatchStatements

      private List<IRCatchClause> compileCatchStatements()
    • wrapInEvalException

      private boolean wrapInEvalException(IType type)
    • createCatchClauseSymbol

      private IRSymbol createCatchClauseSymbol(Symbol symbol, IType type)
    • wrapUndeclaredAsEvaluationException

      private IRStatement wrapUndeclaredAsEvaluationException(IRSymbol catchSymbol, String properName, boolean isBoxed)
    • compileOtherCatchStatements

      private void compileOtherCatchStatements(TopLevelTransformationContext cc, List<CatchClause> otherCatches, List<IRCatchClause> resultingClauses)
      Handle case where a catch clause declares a non-bytecode exception type e.g., soap exception type. In such a case the catch clause and all subsequent catch clauses must be handled in a single catch-clause for Throwable. If none of the subsequent catch clauses handle Throwable explicitly and none of the clauses field the exception, it is rethrown. Note if a 'default' catch clause is declard (i.e. a JavaScript-style catch clause with no exception type declared), it is treated as handling Throwable explicitly; in other words no code is generated to rethrow the exception.

      For example, the following try-catch statement declares a soap exception, which is not really a valid Java exception type. It's a simple case with no finally clause and no default catch, but it illustrates the essence of the problem.

       try {
         doSomething()
       }
       catch( re : RuntimeException ) {
         print( "RuntimeException" )
       }
       catch( fake : DoesntActuallyExtendThrowable ) {
         print( "DoesntActuallyExtendThrowable" )
       }
       catch( e : RealException ) {
         print( "RealException" )
       }
       
      We must treat this statement as the following (simplified) code:
       try {
         doSomething()
       }
       catch( re : RuntimeException ) {
         print( "RuntimeException" )
       }
       catch( t : Throwable ) {
         var rtt = TypeSystem.getFromObject( t )
         if( DoesntActuallyExtendThrowable.Type.isAssignableFrom( rtt ) ) {
           print( "DoesntActuallyExtendThrowable" )
         }
         if( RealException.Type.isAssignableFrom( rtt ) ) {
           print( "RealException" )
         }
         else {
           throw t
         }
       }
       
    • assignCatchClauseSymbol

      private IRStatement assignCatchClauseSymbol(IRSymbol genericCatchSymbol, String expectedName, IType expectedType, boolean isBoxed)
    • reassignCatchSymbol

      private IRStatement reassignCatchSymbol(IRType symbolType, String properName, IRExpression rootValue)
    • wrapCatchSymbol

      private IRExpression wrapCatchSymbol(IRExpression rootValue)
    • boxCatchSymbol

      private IRStatement boxCatchSymbol(IRType componentType, String properName, IRExpression rootValue)