如何创建定制异常类-C#入门经典教程

时间:2024-05-13 13:36:45
【文件属性】:

文件名称:如何创建定制异常类-C#入门经典教程

文件大小:4.81MB

文件格式:PPT

更新时间:2024-05-13 13:36:45

c#

如何创建定制异常类 using System; public class NoDescException : ApplicationException { public NoDescException() { } public NoDescException(string message) : base(message) { } public NoDescException(string message, Exception innerEx) : base(message, innerEx) { } } public interface IFun1 { string ShowMe();} public interface IFun2 { string ShowMe(); } class Circle : IFun1 { public string ShowMe() { return "Circle-IFun1"; } } public class ObjShowMe { public static void ShowMe(object obj) { if (!(obj is IFun1 && obj is IFun2)) { throw new NoDescException("Interface not implemented for " + obj.ToString()); } } } public class MyApp { static void Main() { Circle myCir = new Circle(); try { ObjShowMe.ShowMe(myCir); } catch (NoDescException ex) { Console.WriteLine(ex.Message); } } }


网友评论