while循环用try catch java

时间:2013-04-17 15:59:27

标签: java while-loop try-catch continue

所以出于某种原因,在我的while循环中有一个try catch,当catch触发时,由于某种原因,catch块之后的代码仍在catch块内执行continue语句。所以我不知道发生了什么。

    ArrayList<File> mapFileList = new ArrayList<File>();
    HashMap<String,Map> mapHash = new HashMap<String,Map>();

    // Player Variables
    ArrayList<Player> playerList = new ArrayList<Player>();
    Iterator<Player> playerIter;
    HashMap<String,Stats> statsMap = new HashMap<String,Stats>();
    File playerStatsFile;
    File newPlayerStatsFile;

    /*
     * Choose a map or make a new one
     */
    // Make a list of all existing files
    File mapFolder = new File("bin/maps/");
    // If the maps folder does not already exist, make it
    if(mapFolder.mkdir()){
        System.out.println("Maps folder does not exist. Creating.");
    }
    // For ever map file in the directory, save it to the map file list
    for(File fMap : mapFolder.listFiles()){
        if(fMap.getName().endsWith(".map")){
            mapFileList.add(fMap);
        }
    }
    // Load those maps into the mapHash HashMap
    Iterator<File> itMap = mapFileList.iterator();

        while(itMap.hasNext()){
        Map map = null;
        File fMap;
        // Get each map
        fMap = itMap.next();
        // Load them into memory and deserialize the map
        try{
            MapReader.openFile(fMap);
        }catch(IOException e){
            System.out.println("Error: Cannot open file.");
            continue;
        }

        try{
            map = MapReader.readRecords();
        }catch(Exception e){
            System.out.println("Error: Problem with reading the map.");
            //System.exit(1);
            continue;
        }
        // Let the user know the map loaded successfully
        System.out.println("Map "+map.getName()+" loaded.");
        // Then store the map into the mapHash
        mapHash.put(map.getName().toLowerCase(), map);
    }

0 个答案:

没有答案