zoukankan      html  css  js  c++  java
  • 异常类(Example5_18/Example5_19)

    public class Example5_18{
     public static void main(String arg[]){
      int n=0,m=0,t=0;
      try{
       t=9999;
       m=Integer.parseInt("8888");
       n=Integer.parseInt("12s3a");
       System.out.println("我没有机会输出");
      }
      catch(Exception e){
       System.out.println("发生异常");
       n=123;
     }
     System.out.println("n="+n+",m="+m+",t="+t);
    }
    }

    class MyException extends Exception{
     String message;
     MyException(int n){
      message=n+"不是整数";
     }
     public String getMessage(){
      return message;
     }
    }
    class A{
     public void f(int n) throws MyException{
      if(n<0){
       MyException ex=new MyException(n);
       throw(ex);
      }
      double number=Math.sqrt(n);
      System.out.println(n+"的平方根:"+number);
     }
    }
    public class Example5_19{
     public static void main(String arg[]){
      A a=new A();
      try{
       a.f(28);
       a.f(-8);
      }
      catch(MyException e){
       System.out.println(e.getMessage());
      }
     }
    }

  • 相关阅读:
    序列操作
    上帝造题的七分钟2 / 花神游历各国
    火柴排队
    pair(对组)用法
    线段树
    链上分治
    Rem与Px的转换
    css中单位px和em,rem的区别
    css网页自适应-1
    css网页自适应-2
  • 原文地址:https://www.cnblogs.com/wangchunmeix/p/3040686.html
Copyright © 2011-2022 走看看