public static void main(String s[])
{
Thread t=Thread.currentThread();
t.setName("main");
try
{
for(int i=0;i<=5;i++)
{
System.out.println(i);
Thread.sleep(1000);//interrupted exception(System provides error on its own)
}
}
catch(InterruptedException e)
{
System.out.println("main thread interrupted");
}
}
`예외 상황이있을 때 컨트롤이 catch로 이동하여 코드를 남깁니다. 우리가 thread.sleep을 사용하고 interruptedException에 대한 catch를 만들면 왜 계속 실행됩니까? 그 대신에. 이 코드는 for 루프가 처음 실행될 때 thread.sleep을 만날 때 "0"을 출력하므로 interruptedexception이 발생하면 SO.O.P를 catch하고 실행하고 종료해야합니까?왜 처음 catch에서 thread.sleep이 멈 춥니 까?
음 ... 'sleep'이 종료되는 예외를 트리거 했습니까? –
당신이 말하지 않으면 왜 끝내겠습니까? –