/****************************************************************************** Copyright 2005-2007 R2@DevFx.NET DevFx.NET is free software; you can redistribute it and/or modify it under the terms of the Lesser GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. DevFx.NET is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public License for more details. You should have received a copy of the Lesser GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA /*******************************************************************************/ using System; namespace NOVA.DevFx.ExceptionManagement { /// /// 异常模块异常,框架的基础异常类,所有的异常请从本类派生 /// [Serializable] public class BaseException : Exception { /// /// 构造函数 /// public BaseException() : this(0, null, null) { } /// /// 构造函数 /// /// 异常消息 /// 内部异常 public BaseException(string message, Exception innerException) : this(0, message, innerException) { } /// /// 构造函数 /// /// 异常消息 public BaseException(string message) : this(0, message) { } /// /// 构造函数 /// /// 异常编号 /// 异常消息 public BaseException(int errorNo, string message) : this(errorNo, message, null) { } /// /// 构造函数 /// /// 异常编号 /// 异常消息 /// 内部异常 public BaseException(int errorNo, string message, Exception innerException) : base(message, innerException) { this.errorNo = errorNo; } /// /// 异常编号 /// protected int errorNo; /// /// 异常编号 /// public int ErrorNo { get { return this.errorNo; } } /// /// 查找原始的异常 /// /// 异常 /// 原始的异常 public static Exception FindSourceException(Exception e) { Exception e1 = e; while(e1 != null) { e = e1; e1 = e1.InnerException; } return e; } /// /// 从异常树种查找指定类型的异常 /// /// 异常 /// 期待的异常类型 /// 所要求的异常,如果找不到,返回null public static Exception FindSourceException(Exception e, Type expectedExceptionType) { while(e != null) { if(e.GetType() == expectedExceptionType) { return e; } e = e.InnerException; } return null; } } }