求一个自定义异常类
如题所示.谢谢.
------解决方案--------------------public class MyErr:Exception
{
public MyErr()
{
}
public override string Message
{
get
{
return "我自定义的异常! ";
}
}
}
------解决方案--------------------你要多全的类?
[Serializable]
public sealed class SqlException : DbException
{
private SqlErrorCollection _errors;
private SqlException(SerializationInfo si, StreamingContext sc) : base(si, sc)
{
this._errors = (SqlErrorCollection) si.GetValue( "Errors ", typeof(SqlErrorCollection));
base.HResult = -2146232060;
}
private SqlException(string message, SqlErrorCollection errorCollection) : base(message)
{
base.HResult = -2146232060;
this._errors = errorCollection;
}
internal static SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < errorCollection.Count; i++)
{
if (i > 0)
{
builder.Append(Environment.NewLine);
}
builder.Append(errorCollection[i].Message);
}
SqlException exception = new SqlException(builder.ToString(), errorCollection);
exception.Data.Add( "HelpLink.ProdName ", "Microsoft SQL Server ");
if (!ADP.IsEmpty(serverVersion))
{
exception.Data.Add( "HelpLink.ProdVer ", serverVersion);
}
exception.Data.Add( "HelpLink.EvtSrc ", "MSSQLServer ");
exception.Data.Add( "HelpLink.EvtID ", errorCollection[0].Number.ToString(CultureInfo.InvariantCulture));
exception.Data.Add( "HelpLink.BaseHelpUrl ", "http://go.microsoft.com/fwlink ");
exception.Data.Add( "HelpLink.LinkId ", "20476 ");
return exception;
}
[SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo si, StreamingContext context)
{
if (si == null)
{
throw new ArgumentNullException( "si ");
}
si.AddValue( "Errors ", this._errors, typeof(SqlErrorCollection));
base.GetObjectData(si, context);
}
private bool ShouldSerializeErrors()
{
if (this._errors != null)
{
return (0 < this._errors.Count);
}
return false;
}
public byte Class
{
get
{
return this.Errors[0].Class;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public SqlErrorCollection Errors
{
get
{
if (this._errors == null)
{
this._errors = new SqlErrorCollection();
}
return this._errors;
}
}
public int LineNumber
{
get
{
return this.Errors[0].LineNumber;
}
}
public int Number
{
get
{
return this.Errors[0].Number;
}
}
public string Procedure
{
get
{
return this.Errors[0].Procedure;
}
}
public string Server
{
get
{
return this.Errors[0].Server;
}
}