프로그램에서 IndexOutOfBoundsException이 발생할 수 있다고 가정합니다. 나는 다음과 같은 방법으로 처리하고 있습니다 :try {} catch() {} 블록을 사용하여 자세한 오류 메시지를 표시하는 방법
try{
//throws an IndexOutOfBoundsException during runtime
}catch(IndexOutOfBoundsException ex){
System.err.println(ex);
}
이는 java.lang.IndexOutOfBoundsException를 표시합니다. 그러나 우리가 오류를 처리하지 않을 때 Java가 우리에게 제공하는 것과 같은 (lineNumber, fileName 등) 자세한 오류 메시지 (프로그램을 종료하지는 않음)를 표시하여 프로그램을 종료하고 싶습니다. 콘솔 출력이 어디에 당신이 환경에서 실행하는 경우
try {
int[] x = new int[1];
x[2] = 5;
} catch (IndexOutOfBoundsException ex) {
ex.printStackTrace();
}
System.err.println("Program completed successfully");
:
사용 ex.printStackTrace()가 –