zoukankan      html  css  js  c++  java
  • 0923异常——练习题目作业

    package exception;
    
    public class TestException {
    		public static void main(String[] args)
    		{
    	    for(int i=0;i<4;i++)
    	    {
    	    	
    	    	
    	    	
    	    	
    	try
    	{
    				int k;
    				switch(i)
    				{           
    				case 0: int zero=0;k=911/zero;break;                     
    //            	case 1: int b[]=null;k=b[0];break;
    //           	case 2: int c[]=new int[2];k=c[9];break;
    //           	case 3: char ch="abc".charAt(99);break;
    				} 
    	} 
        catch(Exception e)
        {
        	System.out.println("分母不能为0  "+"错误提示如下");
        	e.printStackTrace();
           	 
        }
    	
    	
    	
    	    }
    		} 
    }
    

      

    package exception;
    
    public class TestException {
    		public static void main(String[] args)
    		{
    	    for(int i=0;i<4;i++)
    	    {
    	    	
    	    	
    	    	
    	    	
    	try
    	{
    				int k;
    				switch(i)
    				{           
    //				case 0: int zero=0;k=911/zero;break;                     
                	case 1: int b[]=null;k=b[0];break;
    //           	case 2: int c[]=new int[2];k=c[9];break;
    //           	case 3: char ch="abc".charAt(99);break;
    				} 
    	} 
        catch(Exception e)
        {
        	System.out.println("空指针  "+"错误提示如下");
        	e.printStackTrace();
           	 
        }
    

      

    package exception;
    
    public class TestException {
    		public static void main(String[] args)
    		{
    	    for(int i=0;i<4;i++)
    	    {
    	    	
    	    	
    	    	
    	    	
    	try
    	{
    				int k;
    				switch(i)
    				{           
    //				case 0: int zero=0;k=911/zero;break;                     
    //            	case 1: int b[]=null;k=b[0];break;
               	case 2: int c[]=new int[2];k=c[9];break;
    //           	case 3: char ch="abc".charAt(99);break;
    				} 
    	} 
        catch(Exception e)
        {
        	System.out.println("超出数组长度  "+"错误提示如下");
        	e.printStackTrace();
           	 
        }
    	
    

      

    package exception;
    
    public class TestException {
    		public static void main(String[] args)
    		{
    	    for(int i=0;i<4;i++)
    	    {
    	    	
    	    	
    	    	
    	    	
    	try
    	{
    				int k;
    				switch(i)
    				{           
    //				case 0: int zero=0;k=911/zero;break;                     
    //            	case 1: int b[]=null;k=b[0];break;
    //           	case 2: int c[]=new int[2];k=c[9];break;
               	case 3: char ch="abc".charAt(99);break;
    				} 
    	} 
        catch(Exception e)
        {
        	System.out.println("输入的字符串错误  "+"错误提示如下");
        	e.printStackTrace();
           	 
        }
    	
    	
    	
    	    }
    		} 
    }
    

      

  • 相关阅读:
    Python-理解装饰器
    PHP-四种解析XML文件的方法
    学习-短信的上行(MO)和下行(MT)详解
    Linux-进程、进程组、作业、会话、控制终端详解
    Linux-进程基础
    Linux-查看进程的完整路径
    Linux-使用 screen 管理你的远程会话
    Python-常用字符串转换实例
    Python-闭包详解
    Git-Git Book阅读笔记
  • 原文地址:https://www.cnblogs.com/zhangnaitao/p/5901878.html
Copyright © 2011-2022 走看看