private object HandleInvocationException(object o, IInternalContextAdapter context, System.Exception t) { /* * In the event that the invocation of the method * itself throws an exception, we want to catch that * wrap it, and throw. We don't Log here as we want to figure * out which reference threw the exception, so do that * above */ /* * let non-Exception Throwables go... */ if (t is System.Exception) { try { return(EventHandlerUtil.MethodException(rsvc, context, o.GetType(), methodName, (System.Exception)t)); } /** * If the event handler throws an exception, then wrap it * in a MethodInvocationException. Don't pass through RuntimeExceptions like other * similar catchall code blocks. */ catch (System.Exception e) { throw new MethodInvocationException("Invocation of method '" + methodName + "' in " + o.GetType() + " threw exception " + e.ToString(), e, methodName, TemplateName, this.Line, this.Column); } } else { /* * no event cartridge to override. Just throw */ throw new MethodInvocationException("Invocation of method '" + methodName + "' in " + o.GetType() + " threw exception " + t.ToString(), t, methodName, TemplateName, this.Line, this.Column); } }
/// <seealso cref="NVelocity.Runtime.Paser.Node.SimpleNode.Execute(java.lang.Object, org.apache.velocity.context.InternalContextAdapter)"> /// </seealso> public override object Execute(object o, IInternalContextAdapter context) { IVelPropertyGet vg = null; try { /* * first, see if we have this information cached. */ IntrospectionCacheData icd = context.ICacheGet(this); /* * if we have the cache data and the class of the object we are * invoked with is the same as that in the cache, then we must * be allright. The last 'variable' is the method name, and * that is fixed in the template :) */ if (icd != null && (o != null) && (icd.ContextData == o.GetType())) { vg = (IVelPropertyGet)icd.Thingy; } else { /* * otherwise, do the introspection, and cache it. Use the * uberspector */ vg = rsvc.Uberspect.GetPropertyGet(o, identifier, uberInfo); if (vg != null && vg.Cacheable && (o != null)) { icd = new IntrospectionCacheData(); icd.ContextData = o.GetType(); icd.Thingy = vg; context.ICachePut(this, icd); } } } /** * pass through application level runtime exceptions */ catch (System.SystemException e) { throw e; } catch (System.Exception e) { string msg = "ASTIdentifier.Execute() : identifier = " + identifier; log.Error(msg, e); throw new VelocityException(msg, e); } /* * we have no getter... punt... */ if (vg == null) { if (strictRef) { throw new MethodInvocationException("Object '" + o.GetType().FullName + "' does not contain property '" + identifier + "'", null, identifier, uberInfo.TemplateName, uberInfo.Line, uberInfo.Column); } else { return(null); } } /* * now try and Execute. If we Get a MIE, throw that * as the app wants to Get these. If not, Log and punt. */ try { return(vg.Invoke(o)); } catch (System.Reflection.TargetInvocationException ite) { /* * if we have an event cartridge, see if it wants to veto * also, let non-Exception Throwables go... */ System.Exception t = ite.GetBaseException(); if (t is System.Exception) { try { return(EventHandlerUtil.MethodException(rsvc, context, o.GetType(), vg.MethodName, (System.Exception)t)); } /** * If the event handler throws an exception, then wrap it * in a MethodInvocationException. Don't pass through RuntimeExceptions like other * similar catchall code blocks. */ catch (System.Exception) { throw new MethodInvocationException("Invocation of method '" + vg.MethodName + "'" + " in " + o.GetType() + " threw exception " + ite.GetBaseException().ToString(), ite.GetBaseException(), vg.MethodName, TemplateName, this.Line, this.Column); } } else { /* * no event cartridge to override. Just throw */ throw new MethodInvocationException("Invocation of method '" + vg.MethodName + "'" + " in " + o.GetType() + " threw exception " + ite.GetBaseException().ToString(), ite.GetBaseException(), vg.MethodName, TemplateName, this.Line, this.Column); } } catch (System.ArgumentException) { return(null); } /** * pass through application level runtime exceptions */ catch (System.SystemException e) { throw e; } catch (System.Exception e) { string msg = "ASTIdentifier() : exception invoking method " + "for identifier '" + identifier + "' in " + o.GetType(); log.Error(msg, e); throw new VelocityException(msg, e); } }