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
    }
}

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
    }
}

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;
        }

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
                });
            }
        }

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);
                }

MyException

时间: 2024-12-11 02:39:14

MyException的相关文章

Java必知必会:异常机制详解

一.Java异常概述 在Java中,所有的事件都能由类描述,Java中的异常就是由java.lang包下的异常类描述的. 1.Throwable(可抛出):异常类的最终父类,它有两个子类,Error与Exception. Throwable中常用方法有: getCause():返回抛出异常的原因.如果 cause 不存在或未知,则返回 null. getMeage():返回异常的消息信息. printStackTrace():对象的堆栈跟踪输出至错误输出流,作为字段 System.err 的值.

【Python&amp;数据结构】 抽象数据类型 Python类机制和异常

这篇是<数据结构与算法Python语言描述>的笔记,但是大头在Python类机制和面向对象编程的说明上面.我也不知道该放什么分类了..总之之前也没怎么认真接触过基于类而不是独立函数的Python编程,借着本次机会仔细学习一下. 抽象数据类型 最开始的计算机语言,关注的都是如何更加有效率地计算,可以说其目的是计算层面的抽象.然而随着这个行业的不断发展,计算机不仅仅用于计算,开发也不仅只关注计算过程了,数据层面的抽象也变得同样重要.虽然计算机语言一开始就有对数据的抽象,但是那些都只是对一些最基本的

SpringMVC学习笔记五:HandlerExceptionResolver异常处理

继承HandlerExceptionResolver自定义异常处理器 控制器ExceptionController.java package com.orange.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.Mode

跟着百度学PHP[11]-PHP当中的异常处理

首先要说一下常见的三种错误: 1.语法错误 2.运行错误 3.逻辑错误 00x1 错误报告及错误级别 PHP的错误分为三个等级 1.注意(notice)   没有变量a 2.警告(warning) 没有给函数传值 3.致命的错误(fatal error) 函数写错 错误的报告级别可以在PHP.ini当中修改.在PHP.ini当中找到错误报告“error_reporting = E_ALL ” 这个的意思是将所有的错误都提示出来.ps:~是除了的意思.&是和的意思.error_reporting

java 异常的捕获及处理

在没有异常处理的程序中如果要回避异常,需要使用大量的判断语句,配合所想到的错误状况来捕捉程序中可能发生的错误.但是这样势必会导致程序运行效率降低.java异常处理机制具有易于使用,可自定义异常类,处理抛出的异常的同时,又不会降低程序运行效率等优点.因而在java程序设计时,应充分的利用异常处理机会,以增进程序的稳定性及效率.1.异常处理示例及基本格式: package javaBasics; public class test5 { public static void main(String[

python3_装饰器_异常处理

装饰器: def auth(func):     def wrapper(name):                     如果函数带参数,要加在这里         user=raw_input("input passwd:").strip()         if user=='test':             print "welcome login"             func(name)              如果函数带参数,要加在这里

动手动脑(异常处理)

1.请阅读并运行AboutException.java示例,然后通过后面的几页PPT了解Java中实现异常处理的基础知识. import javax.swing.*; class AboutException { public static void main(String[] args) { float i=1, j=0, k; k=i/j; System.out.println(k); try { k = i/j;    // Causes division-by-zero exceptio

2.Java异常学习

1.Java异常的概念 异常的例子 1.除法就是一个需要捕获异常的例子,除数又可能是0 异常处理的基本流程如下 一旦发生异常,就使得程序不按照原来的流程继续的运行下去 a.程序抛出异常 try{ throw new Exception(); } b.捕获异常 catch(Exception e){ //异常处理程序 } c.finally代码块 必须注意的是:在finally块中不能抛出异常. finally{ //一定会被执行 //除非catch中有System.exit(0);会推出Java

SASS详解之沿袭(extend)

SASS详解之继承(extend) 每一个类名都有可能有另一个类名的所有样式和它自己的特定样式的.当一个div的身上有两个类名,一个是“one”,另一个是“two”的时候.如下 HTML代码 <div class="one two"> 梦龙小站 </div> CSS代码 .one {width:100px;height:100px;} .two {background:red;border:5px solid #000;} 这就意味着,我们要配备一个很好的记忆力