Class TryCatchFinallyStatementTransformer

    • Method Detail

      • compileCatchStatements

        private java.util.List<IRCatchClause> compileCatchStatements()
      • wrapInEvalException

        private boolean wrapInEvalException​(IType type)
      • createCatchClauseSymbol

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

        private IRStatement wrapUndeclaredAsEvaluationException​(IRSymbol catchSymbol,
                                                                java.lang.String properName,
                                                                boolean isBoxed)
      • compileOtherCatchStatements

        private void compileOtherCatchStatements​(TopLevelTransformationContext cc,
                                                 java.util.List<CatchClause> otherCatches,
                                                 java.util.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,
                                                    java.lang.String expectedName,
                                                    IType expectedType,
                                                    boolean isBoxed)