Beispiel #1
0
        /// <summary>
        ///  构造函数...
        /// </summary>
        /// <param name="clientMsg"></param>
        /// <param name="msgLever"></param>
        /// <param name="innerException"></param>
        public APPException(string clientMsg, APPMessageType msgLever, Exception innerException)
            : base(clientMsg, innerException)
        {
            _MsgLever = msgLever;
            string msg = clientMsg;

            if (innerException != null)
            {
                string innerMsg = string.Empty;
                if (innerException is APPException)
                {
                    APPException appEx = innerException as   APPException;
                    _MsgLever = appEx.MsgLever;
                    innerMsg  = appEx.Message;
                }
                else
                {
                    try {
                        getErrMessage(innerException, ref innerMsg);
                    }
                    catch { }
                }
                TraceEx.Write(innerMsg, APPMessageType.SysErrInfo);
                if (!string.IsNullOrEmpty(innerException.StackTrace))
                {
                    TraceEx.Write(innerException.StackTrace);
                }
            }
            TraceEx.Write(msg, msgLever);
        }
Beispiel #2
0
        /// <summary>
        /// 创建异常。
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="msgLever"></param>
        /// <returns></returns>
        public static APPException PromoteException(Exception ex, APPMessageType defaultMsgLever)
        {
            if (ex is APPException)
            {
                return(ex as APPException);
            }
            else
            {
                APPException aex = new APPException(ex.Message, defaultMsgLever, ex);

                return(aex);
            }
        }
Beispiel #3
0
 private MB.Util.APPException getAppException(Exception ex)
 {
     MB.Util.APPException appEx = ex as MB.Util.APPException;
     if (appEx != null)
     {
         return(appEx);
     }
     else
     {
         if (ex.InnerException != null)
         {
             return(getAppException(ex.InnerException));
         }
         else
         {
             return(null);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// 终止系统产生的异常,并以消息的形式提示给用户。
        /// </summary>
        /// <param name="ex">异常</param>
        /// <param name="expectMsgOnError">出错时期待提示的消息。</param>
        public void ExceptionTerminate(Exception ex, string expectMsgOnError)
        {
            MB.Util.APPException appEx = getAppException(ex);// as MB.Util.APPException;
            string reason = string.Empty;

            if (appEx == null)
            {
                appEx = ex.InnerException as MB.Util.APPException;
            }

            if (appEx != null)
            {
                if (appEx.MsgLever == MB.Util.APPMessageType.DisplayToUser)
                {
                    MessageBoxEx.Show(appEx.Message);

                    return;
                }
                else
                {
                    expectMsgOnError = MB.Util.TraceEx.GetErrorMessageByType(appEx.MsgLever) + " " + appEx.Message;
                }
            }
            else
            {
                System.ServiceModel.FaultException <MB.Util.Model.WcfFaultMessage> fex = ex as System.ServiceModel.FaultException <MB.Util.Model.WcfFaultMessage>;
                if (fex != null)
                {
                    if (fex.Detail != null)
                    {
                        if (fex.Detail.MessageType == MB.Util.APPMessageType.DisplayToUser)
                        {
                            MessageBoxEx.Show(fex.Detail.Message);
                            return;
                        }
                        else
                        {
                            reason = fex.Detail.Message + " " + MB.Util.TraceEx.GetErrorMessageByType(fex.Detail.MessageType);
                        }
                    }
                    else
                    {
                        reason = fex.Message;
                    }
                }
                string msg = string.Empty;
                if (string.IsNullOrEmpty(reason))
                {
                    getErrMessage(ex, ref msg);
                }

                TraceEx.Write(msg, APPMessageType.SysErrInfo);
                if (!string.IsNullOrEmpty(ex.StackTrace))
                {
                    TraceEx.Write(ex.StackTrace, APPMessageType.SysErrInfo);
                }
            }

            if (string.IsNullOrEmpty(expectMsgOnError))
            {
                if (string.IsNullOrEmpty(reason))
                {
                    reason = "系统出现未知的异常,请重试!";
                }
                MessageBoxEx.Show(reason);
            }
            else
            {
                MessageBoxEx.Show("系统错误:" + expectMsgOnError);
            }
        }