软件开发基础9-错误与异常处理.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
关键代码如下: class UserException : Exception //定义用户的异常类 { //重载Exception类的构造函数 public UserException() { } public UserException(string ms):base(ms) { } public UserException(string ms,Exception inner) : base(ms,inner) { } } class student //定义学生类 { private string name; //姓名,长度不超过8个字节 private double score; //成绩,范围为[0,100] public void setInfo(string name, double score) { if (name.Length 8) { throw (new UserException(姓名长度超过了8个字节!)); } if (score 0 || score 100) { throw (new UserException(非法的分数!)); } this.name = name; this.score = score; } } static void Main(string[] args) { student s = new student(); try { s.setInfo(张三, 958.5); } catch (Exception e) { Console.WriteLine(产生异常:{0}, e.Message); } Console.ReadKey(); } 执行该程序 : 在运行过程中由于试图对score赋值958.5,结果导致下列异常被创建和抛出: new UserException(非法的分数!) SAY THIS: Example: “PREPARING TO BUILD A HOUSE.” Looking at the various models leading up to the construction of a house, one usually begins with a sketch of the proposed dwelling. This may be followed by a miniature scale model of the house. Finally, the blueprints are rendered which provide the technical specifications and the mechanical requirements for the builders. Each model gets reviewed and approved before the next stage begins, offering several opportunities to consider design improvements before groundbreaking. Using ERwin, our model creates the Database Schema for the database which will house our data. SAY THIS: Example: “PREPARING TO BUILD A HOUSE.” Looking at the various models leading up to the construction of a house, one usually begins with a sketch of the proposed dwelling. This may be followed by a m

文档评论(0)

a13355589 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档