| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 492 人关注过本帖
标题:关于异常
只看楼主 加入收藏
tottibuffon
Rank: 2
等 级:论坛游民
帖 子:105
专家分:20
注 册:2009-6-5
结帖率:83.87%
收藏
 问题点数:0 回复次数:1 
关于异常
import *;
import java.util.Vector;

public class ListOfNumbers {
    private Vector<Integer> victor;
    private static final int SIZE = 10;

    public ListOfNumbers () {
        victor = new Vector<Integer>(SIZE);
        for (int i = 0; i < SIZE; i++)
            victor.addElement(new Integer(i));//改i-2出现负数异常
    }
    public void writeList() {
        PrintWriter out = null;

        try {
            System.out.println("Entering try statement");
            out = new PrintWriter(new FileWriter("OutFile.txt"));
        
            for (int i = 0; i < SIZE; i++)
                out.println("Value at: " + i + " = " + victor.elementAt(i));//改i-2负数异常
        }
        catch (ArrayIndexOutOfBoundsException e) {
            System.err.println("Caught ArrayIndexOutOfBoundsException: " +
                                 e.getMessage());
        }
        catch (IOException e) {
            System.err.println("Caught IOException: " + e.getMessage());
        }
        catch(NegativeArraySizeException e ){
            System.err.println("Caught NegativeArraySizeException :"+e.getMessage());
        }
        catch(NullPointerException e){
            System.err.println("Caught NullPointerException :"+e.getMessage());
                }
        finally {
            if (out != null) {
                System.out.println("Closing PrintWriter");
                out.close();
            } else {
                System.out.println("PrintWriter not open");
            }
        }
    }
    public static void main(String [] args){
     ListOfNumbers num=new ListOfNumbers();
     num.writeList();
    }
}
问题:这四个异常代表的意思以及如何改动程序会使得IOException NullPointerException NegativeArraySizeException 异常出现?
2009-10-15 17:01
tottibuffon
Rank: 2
等 级:论坛游民
帖 子:105
专家分:20
注 册:2009-6-5
收藏
得分:0 
回复 楼主 tottibuffon
怎么没人回啊?
2009-10-15 22:40
快速回复:关于异常
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022667 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved