Best way to check for inner exception?

后端 未结 14 2258
说谎
说谎 2020-12-02 11:57

I know sometimes innerException is null

So the following might fail:

 repEvent.InnerException = ex.InnerException.Message; 

Is ther

相关标签:
14条回答
  • 2020-12-02 12:41
    class MyException : Exception
    {
        private const string AMP = "\r\nInnerException: ";
        public override string Message
        {
            get
            {
                return this.InnerException != null ? base.Message + AMP + this.InnerException.Message : base.Message;
            }
        }
    
        public override string StackTrace
        {
            get
            {
                return this.InnerException != null ? base.StackTrace + AMP + this.InnerException.StackTrace : base.StackTrace;
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-02 12:48

    That's funny, I can't find anything wrong with Exception.GetBaseException()?

    repEvent.InnerException = ex.GetBaseException().Message;
    
    0 讨论(0)
提交回复
热议问题