0
後,我想拋出一個異常,這是我的代碼調用主闖闖拋出異常
System.out.println("please enter an intger to compute its factorial:");
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
String number ="";
try {
try {
number = bufferedreader.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
intN=Integer.parseInt(number);
if (intN > 0) { // from the command line
FactorialIter f =
new FactorialIter(Math.abs(intN));
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
System.out.println("error you should enter a number");
throw new MyExceptions("try again please use integer numbers");
//if possible to restart the main
}
所以當以往用戶輸入一個字符,程序將拋出一個異常,然後重新啓動後重新啓動程序這可能嗎??
嘗試檢查了這個問題: http://stackoverflow.com/questions/4159802/how-can-i-restart-a-java-application – DrRoach