zoukankan      html  css  js  c++  java
  • JAVA基础篇—异常

    五种常见异常

    1、NullPointerException 空指针

    2、ClassNotFoundException 指定类不存在

    3、ArithmeticException运算异常

    4、ArrayIndexOutOfBoundsException数组下标越界

    5、IllegalArgumentException方法的参数错误

    6、IllegalAccessException 没有访问权限

    小例子

    import java.util.Scanner;
    
    public class Exception {
         
         int shang;
         public Exception(int  chushu,int  beichushu){
        	 
        	 shang=chushu/beichushu;
         }
         public static void main(String[] args) {
        	 try {
        		 Scanner sc=new Scanner(System.in);
    			String chushu=sc.nextLine();
    			String beichushu=sc.nextLine();
    			int a =Integer.parseInt(chushu);
    			int b =Integer.parseInt(beichushu);
    			
    			Exception exception =new Exception(a, b);
    			System.out.println(exception.shang);
    		} catch (NumberFormatException e) {
    			System.out.println("NumberFormatException");
    			e.printStackTrace();
    			// TODO: handle exception
    		}
        	 catch (ArithmeticException e) {
        		 System.out.println("ArithmeticException");
     			// TODO: handle exception
        		 e.printStackTrace();
     		}finally {
    			System.out.println("666");
    		}
    	}
    }
    

      

  • 相关阅读:
    自定义TAB
    android Tabhost部件
    PHP链接MYSQL
    Server.Transfer传值方法的使用
    JQuery一些简单常用的方法
    经典mssql语句大全
    C#中如何将DataTable中的数据写入Excel
    03、JavaEECookie & Session
    08、C# Task的使用
    06、JavaEEJSP基本语法
  • 原文地址:https://www.cnblogs.com/lc-java/p/7396903.html
Copyright © 2011-2022 走看看