public class ExceptionDemo2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int i=0;
int a[]={1,2,3,4};
for( i = 0; i<5; i++)
{
try
{
System.out.print("a[" + i + "]/"+ "=" + (a[i]/i));
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.print("捕获数组下标越界");
}
catch(ArithmeticException e)
{
System.out.print("捕获算术异常");
}
finally
{
System.out.print("finally i=" + i);
}
System.out.println("继续!");
}
}
}
![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTMyMjQ5OS8yMDE4MTEvMTMyMjQ5OS0yMDE4MTExMjE2MDUyMzI1OC0xMTE3ODM2MzUxLnBuZw?x-oss-process=image/format,png)
public class ThrowsDemo {
public static void throwOne() throws IllegalAccessException{
System.out.println("inside throwOne.");
throw new IllegalAccessException("ThrowsDemo");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
throwOne();
}
catch(IllegalAccessException e)
{
System.out.println("Caught" + e);
}
}
}
![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTMyMjQ5OS8yMDE4MTEvMTMyMjQ5OS0yMDE4MTExMjE2MTQ1MDM0Ny0xMTM4OTg2NTc5LnBuZw?x-oss-process=image/format,png)