2014-03-25 21 views
1

我有我的异常处理程序,它用于企业库异常处理。 该处理器包含方法HandleException属性StackTrace不能分配,它是只读的

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

我想记录属性,并在日志文件中看到StackTrace不可用,所以我应该创建处理程序,它将写入所有我需要的 –

+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 ; 
    } 
相关问题