Capgemini / Cauldron

C# Toolkit
MIT License
76 stars 18 forks source link

Reform & Re-throw Exception on OnException Method in IMethodInterceptor #81

Open MAliM1988 opened 5 years ago

MAliM1988 commented 5 years ago

Hello Everyone

I Have Problem With IMethodInterceptor.OnException I Use Cauldron.Interception version 3.2.3 with this code

[InterceptorOptions(AlwaysCreateNewInstance = true)]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class ExceptionInterceptorAttribute : Attribute, IMethodInterceptor, IDisposable
{
    #region Fields

    private Type _declaringType;
    private MethodBase _methodBase;
    private object[] _values;

    #endregion

    #region IMethodInterceptor Members

    public void OnEnter(Type declaringType, object instance, MethodBase methodbase, object[] values)
    {
        _declaringType = declaringType;
        _methodBase = methodbase;
        _values = values;
    }

    public bool OnException(Exception e)
    {
        throw catchHandler(e, _declaringType, _methodBase, _values);
    }

    public void OnExit()
    {

    }

    #endregion

    #region Private Members

    private Exception catchHandler(Exception exception, Type type, MethodBase methodBase, object[] values)
    {
        return new Exception(exception.Message);
    }

    #endregion

    #region IDisposable Members

    public void Dispose()
    {
        _declaringType = null;
        _methodBase = null;
        _values = null;

        GC.SuppressFinalize(this);
    }

    #endregion
}

When i reform exception an re-throw new exception my project debugging has break and project has stopped.

I replace body of OnException with this (re-throw without reform exception)

    public bool OnException(Exception e)
    {
        catchHandler(e, _declaringType, _methodBase, _values);

        return true;
    }

debugging mode is run and back to host of project,how can i reform and re-throw exception with or without return true?