码迷,mamicode.com
首页 > 其他好文 > 详细

0923异常——练习题目作业

时间:2016-09-23 23:14:17      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

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();
       	 
    }
	
	
	
	    }
		} 
}

  技术分享

0923异常——练习题目作业

标签:

原文地址:http://www.cnblogs.com/zhangnaitao/p/5901878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!