当数组超出范围时,有没有办法跳过当前命令?
memory[count] = allProcesses[processIndex[index]+temp];
当数组试图访问一个不存在的变量时,它会越界。我只想打印一条错误消息并继续运行,但每次发生时,程序都会终止
我试过的:
try {
memory[count] = allProcesses[processIndex[index]+temp];
} catch (Exception e) {
System.out.println("Page Fault");
Thread.sleep(2000);
}
这是错误消息:
...
Adding Process 10, address 48214, page 1868, offset 12, value 550 to memory location 54
Adding Process 11, address 30649, page 557, offset 13, value 229 to memory location 55
Adding Process 11, address 46819, page 343, offset 7, value 519 to memory location 56
Adding Process 11, address 54762, page 94, offset 14, value 425 to memory location 57
Page Fault
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 726384
at MMU.MMUProcess(MMU.java:58)
at Driver.main(Driver.java:73)