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

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