업데이트 나는이 다음과 같은 자바 코드 골격이 -예외 -
try {
Question q = null; //List of questions. I have put 3 in the list, in my main function
int i = 0;
while (i <= questions.size()) {
System.out.println("iteration " + i);
q = questions.get(i);
try {
try {
System.out.println("Script completed");
break;
} catch (Exception e) {
// script is still executing... continue
}
//My entire logic is here.An exception is thrown in the first iteration
i++;
} catch (Exception e) {
//The thrown exception is caught here
try {
//The caught exception is handled here
} catch (IOException ioe) {
System.out.println("IO Exception..");
}
}
}
} catch (IOException ioe) {
System.out.println("No more communication due to the lack of data");
} catch (IllegalMonitorStateException imse) {
System.out.println("Illegal Monitor State Exception");
} catch (IllegalThreadStateException itse) {
System.out.println("Illegal Thread State Exception");
}
그리고 출력을 내가 얻을는 다음과 같이 다소이다 -
iteration 0
//Exception handling related output
iteration 0 //repeated because i++ doesn't happen since exception is thrown
//Execution takes place normally
iteration 1
//???????? - Here is where i am facing the problem. I am not getting
출력 완전히. 내가 반복 1에있는 이유를 알고있다. (처음으로 던진 예외 때문에 한번도 발생하지 않는 ++와 관련이있다.) 하지만 아무도 나를이 반복을 성공적으로 수행하는 방법을 도울 수 있습니까?
여기에 정보가 충분하지 않습니다. –
[SSCCE] (http://sscce.org/)를 제공하면 더 나은 답변을 얻을 수있을뿐만 아니라 사용자가 직접 작성하여 도움을 얻을 수도 있습니다. 앞으로도 그렇게 해보십시오! –
세계 여러 곳에서 왜 예외를 잡을 필요가 있습니까? 이런 중첩 된 try 블록은 거대한 코드 냄새입니다. –