属性StackTrace无法分配,它是只读的

时间:2014-03-25 22:01:23

标签: exception enterprise-library

我有我的异常处理程序,用于企业库异常处理。 此处理程序包含方法HandleException

public Exception HandleException(Exception exception, Guid handlingInstanceId)
        {

            Exception wrap = new Exception();
            wrap.StackTrace = exception.StackTrace;
            return wrap;
        }

当我尝试将收到的exception.StackTrace属性分配给变量wrap时,我收到错误:

property or indexer 'System.Exception.StackTrace' cannot be assigned to -- it is read only

如何将其分配给我的变量?

1 个答案:

答案 0 :(得分:0)

这通常是我所见过的。

    public Exception HandleException(Exception exception, Guid handlingInstanceId)
    {

        //Do something with the Exception.

       return exception;
    }

    public Exception HandleException(Exception exception, Guid handlingInstanceId)
    {

        ApplicationException appEx = new ApplicationException(exception.Message, exception);

       return appEx ;
    }
相关问题