zoukankan      html  css  js  c++  java
  • MyException

    自定义Exception

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.Serialization;
    
    namespace Model
    {
        /// <summary>
        /// This class is used to define the custom exception.
        /// </summary>
        [DataContract]
        public class MyExceptionContainer:Exception
        {
            /// <summary>
            /// The exception's starck message.
            /// </summary>
            [DataMember]
            public string ErrorMessage { get; set; }
    
            /// <summary>
            /// The custom informtion.
            /// </summary>
            [DataMember]
            public string Description { get; set; }
    
            #region Constructor
    
            public MyExceptionContainer() { }
    
            public MyExceptionContainer(string errorMessage, string description)
            {
                this.ErrorMessage = errorMessage;
                this.Description = description;
            }
    
            #endregion
        }
    }
    View Code

    UserException

    using System;
    using System.Runtime.Serialization;
    using System.Security.Permissions;
    
    namespace Constant
    {
        /// <summary>
        /// The class is defined for const fields of login exception.
        /// </summary>
        [Serializable]
        public class UserException:Exception,ISerializable
        {
            #region Fields
    
            private string message;
            private Exception innerException;
    
            #endregion
    
            #region Constructors
    
            public UserException() { }
    
            public UserException(string message)
            {
                this.message = message;
            }
    
            public UserException(string message, Exception exception)
            {
                this.message = message;
                this.innerException = exception;
            }
    
            #endregion
    
            #region Const fileds of user functions' exception.
    
            public const string UserNameIsNull = "*Username is null.";
            public const string PasswordIsNull = "*Password is null.";
            public const string LoginedFailed = "*Username or password is wrong.";
            public const string ChangeNewPasswordIsNull = "*New password is null.";
            public const string ChangeConfirmIsNull = "*Confirm is null.";
            public const string TwiceEnterIsNotSame = "*New password and confirm is not same.";
            public const string PasswordIsWrong = "*Old Password is wrong.";
            public const string UpdatePasswordFailed = "The error is come from UpdatePasswordFailed Method in UserDal Class.";
            public const string RetrieveUserByUserName = "The error is come from RetrieveUserByUserName Method in UserDal Class.";
            public const string ChangePasswordSucceed = "Change password succeed.";
            public const string FormatException = "The parameter error.";
    
            #endregion
        }
    }
    View Code

    DAL

            public int UpdatePassword(string newPassword, string userName)
            {
                int influenceNumber = 0;
    
                try
                {
                    string sqlText = SqlText.UpdatePassword;
                    SqlParameter[] parms = new SqlParameter[] {
                        new SqlParameter("@password", newPassword),
                        new SqlParameter("@userName", userName),
                    };
    
                    influenceNumber = SqlHelper.ExecuteNonQuery(sqlText, parms);
                }
                catch (SqlException ex)
                {
                    throw new UserException(UserException.UpdatePasswordFailed, ex);
                }
    
                return influenceNumber;
            }
    View Code

    BLL

            public IList<Exam> RetrieveExamList(string userName, int order)
            {
                try
                {
                    return examDal.RetrieveExamList(userName, order);
                }
                catch (ExamException ex)
                {
                    log.Error(ExamException.RetrieveExamList, ex);
                    throw new FaultException<MyExceptionContainer>( new MyExceptionContainer() {
                        ErrorMessage = ex.Message,
                        Description = ExamException.RetrieveExamList
                    });
                }
            }
    View Code
    Use
                    catch (FaultException<MyExceptionContainer> myException)
                    {
                        log.Error(myException.Message, myException);
                    }
                    catch (FaultException faultException)
                    {
                        log.Error(faultException.Message, faultException);
                    }
                    catch (Exception exception)
                    {
                        log.Error(exception.Message, exception);
                    }
    View Code
  • 相关阅读:
    AtCoder AGC036C GP 2 (组合计数)
    Luogu P4708 画画 (Burnside引理、组合计数、划分数)
    BZOJ 1488 Luogu P4727 [HNOI2009]图的同构 (Burnside引理、组合计数)
    BZOJ 2655 calc (组合计数、DP、多项式、拉格朗日插值)
    POJ 1430 Binary Stirling Numbers (第二类斯特林数、组合计数)
    BZOJ 4555 Luogu P4091 [HEOI2016/TJOI2016]求和 (第二类斯特林数)
    Luogu P4707 重返现世 (拓展Min-Max容斥、DP)
    LOJ #6358 前夕 (组合计数、容斥原理)
    BZOJ 3622 Luogu P4859 已经没有什么好害怕的了 (容斥原理、DP)
    Java基本的程序结构设计 大数操作
  • 原文地址:https://www.cnblogs.com/chenyongblog/p/3819200.html
Copyright © 2011-2022 走看看