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 = ; 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
});
}
}
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的更多相关文章
- http://www.myexception.cn/program/767123.html
http://www.myexception.cn/program/767123.html
- 31.3 自定义异常类 MyException
/* * 异常的分类: 运行时期异常:RuntimeException的子类就是运行时期异常,在编译时期可以自由选择处理或者不处理 编译时期异常:是Exception的子类,非RuntimeExcpe ...
- PHP验证用户登录例子-学习笔记
1.基本流程: 2.UML类图: 3.PHP代码: 3.1 index.php <?php /** * Created by PhpStorm. * User: andy * Date: 16- ...
- [C#] C# 知识回顾 - 你真的懂异常(Exception)吗?
你真的懂异常(Exception)吗? 目录 异常介绍 异常的特点 怎样使用异常 处理异常的 try-catch-finally 捕获异常的 Catch 块 释放资源的 Finally 块 一.异常介 ...
- [C#] C# 知识回顾 - 学会使用异常
学会使用异常 在 C# 中,程序中在运行时出现的错误,会不断在程序中进行传播,这种机制称为“异常”. 异常通常由错误的代码引发,并由能够更正错误的代码进行 catch. 异常可由 .NET 的 CLR ...
- [干货来袭]C#6.0新特性
微软昨天发布了新的VS 2015 ..随之而来的还有很多很多东西... .NET新版本 ASP.NET新版本...等等..太多..实在没消化.. 分享一下也是昨天发布的新的C#6.0的部分新特性吧.. ...
- C# BackgroundWorker 详解
在C#程序中,经常会有一些耗时较长的CPU密集型运算,如果直接在 UI 线程执行这样的运算就会出现UI不响应的问题.解决这类问题的主要途径是使用多线程,启动一个后台线程,把运算操作放在这个后台线程中完 ...
- 浅谈Java的throw与throws
转载:http://blog.csdn.net/luoweifu/article/details/10721543 我进行了一些加工,不是本人原创但比原博主要更完善~ 浅谈Java异常 以前虽然知道一 ...
- 札记:Java异常处理
异常概述 程序在运行中总会面临一些"意外"情况,良好的代码需要对它们进行预防和处理.大致来说,这些意外情况分三类: 交互输入 用户以非预期的方式使用程序,比如非法输入,不正当的操作 ...
随机推荐
- pyenv的安装和使用
1. 先安装crul和git sudo apt-get install curl git-core 2. 安装pyenv curl https://raw.github.com/yyuu/pyenv- ...
- 转:YUV RGB 常见视频格式解析
转: http://www.cnblogs.com/qinjunni/archive/2012/02/23/2364446.html YUV RGB 常见视频格式解析 I420是YUV格式的一种,而Y ...
- 重磅消息:JavaFX官方文档翻译完毕
经过XMan团队业余时间半年的努力,终于将JavaFX官方文档全部翻译完毕,内容已经全部在http://www.javafxchina.net中发表. 中文文档具体目录如下: 第一篇 开始学习Java ...
- jquery 触发a链接点击事件
jquery 触发a链接点击事件 <p class="btnSubmit"><a href="javascript:submitData();" ...
- 关于async与await的FAQ 转
(译)关于async与await的FAQ 传送门:异步编程系列目录…… 环境:VS2012(尽管System.Threading.Tasks在.net4.0就引入,在.net4.5中为其增加了更丰富的 ...
- 了解ASP.NET MVC几种ActionResult的本质:HttpStatusCodeResult & RedirectResult/RedirectToRouteResult
在本系列的最后一篇,我们来讨论最后三个ActionResult:HttpStatusCodeResult.RedirectResult和RedirectToRouteResult .第一个用于实现针对 ...
- 坑到了,EF执行带事物的存储过程
用EF开发项目,今天调用 带事物 存储过程,始终报错,"EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配.上一计数 = 1,当前计数 = 0.\r\nEXEC ...
- 在远程系统上开发 SharePoint 应用程序
适用范围: apps for SharePoint | Office 365 | SharePoint Foundation 2013 | SharePoint Server 2013 使用远程安装的 ...
- 使用jquery插件报错:TypeError:$.browser is undefined的解决方法
关于$.browser browser就是用来获取浏览器基本信息的. jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.sup ...
- js 动态添加元素(div、li、img等)及设置属性
把一串 html 标签赋给一个 javascript 变量,除属性的值要用转义的双引号外,某些时候字符串还很长,显得有些复杂.如果用 js 动态添加元素,就不会有那么复杂的字符串出现,代码阅读性强一点 ...