zoukankan      html  css  js  c++  java
  • 《C#入门详解》刘老师 表达式,语句详解

    class program
    {
     static void main(string[] args)
     {
      calculator c = new calculator();
      int r           = 0;
      try
      {
       r               = c.add("abc","100");
       }
       catch(overflowException oe)
       {
       console.writeline(oe.message);
        }
      }
    }
    
    class Calculator
    {
      public int Add(string arg1 , string arg2)
      {
       int a = 0;
       int b = 0;
       try
       {
        a = int.parse(arg1);
        b = int.parse(arg2);
        }
        catch(ArgumentNullException)
        {console.writeling("your arguments are null");}
        catch(FormatException)
        {console.writeling("your arguments are not number");}    
        catch(OverFlowException oe)
        {
          //console.writeline("out of range");
         throw oe;//只希望处理上面的两个异常,把overflow这个异常抛出去,意思是谁调用          这个add方法,谁去抓住这个异常进行处理
         }
    /*可以在catch后面的圆括号内加上标识符( catch(ArgumentNullException ane)),可以打印出具体错误消息。*/
    /*try catch finally,当执行try语句的时候,无论是否发生异常,finally语句永远会执行,finally语句中一般会写两类内容,第一类数据库链接总能关闭,第二类写程序的log*/
      }
    }
  • 相关阅读:
    Smali语法
    css 实现垂直水平居中常用方法
    css border实现三角形
    vue-router学习笔记
    vuex状态管理
    es6 reduce的用法
    vue学习笔记
    chrome调式工具
    前端需要了解的http知识
    underscore.js and moment.js
  • 原文地址:https://www.cnblogs.com/zfcsharp/p/13715197.html
Copyright © 2011-2022 走看看