namespace programming { class Program { static void Main(string[] args) { Test t = new Test(); try { t.bb = -3; } catch (Exception e) { Console.WriteLine(e.Message); } finally { Console.WriteLine("finally!"); } } } class Test { int aa; public int bb { get { return aa; } set { if (value >= 0) aa = value; else throw (new Myexception()); } } } class Myexception : Exception { public Myexception() : base("This is an error!!") { } public Myexception(string message) : base(message) { } public Myexception(string message, Exception e) : base(message, e) { } } }
c系列之异常的抛出
最新推荐文章于 2024-03-27 12:21:02 发布