나는 던지기가 언제 사용되고 던짐이 사용되는지 명확하게 이해하기가 혼란 스럽다. 친절하게 저에게 차이를 보여주기위한 모범을 보여주십시오.자바에서 던지기와 던지기의 차이 - 명확화
또한, 나는 아래의 코드를 시도 :
패키지 AccessModifiers을;
// import java.io.IOException;
공용 클래스 ThrowExceptions {
int QAAutoLevel;
int QAExp;
void QAAutomationHiring(int grade)
{
if (grade<5)
throw new ArithmeticException("Not professionally Qualified");
else
System.out.println("Ready to be test");
}
void QAExperience(int x,int grade)
{
QAAutomationHiring(grade);
}
void checkThrowsExep(int a,int b) throws ArithmeticException
{
try{
int result=a/b;
System.out.println("Result is :"+result);
}
catch(Exception e)
{
System.out.println("The error messgae is: "+ e.getMessage());
}
}
public static void main(String args[])
{
ThrowExceptions t=new ThrowExceptions();
//t.QAAutomationHiring(8);
t.QAExperience(2,8);
t.QAExperience(4,2);
t.checkThrowsExep(5, 0);
}
} 위의 코드에서
, 내가 프로그램을 실행할 때 주요 기능의 라인 - 't.checkThrowsExp은'도달하지 않습니다. 나는 throw와 throw가 예외를 잡아 내고 프로그램 실행을 계속하는 데 사용된다는 것을 연구했다. 그러나 여기에서는 실행이 중단되고 다음 명령문 세트로 진행되지 않습니다. 의견을 공유하십시오.
예외를 throw하려는 경우'throw'가 사용됩니다. 'throws'는 호출자가 무엇을 잡아야 하는지를 알기 위해 던져지는 어떤 예외적 인 예외가 메소드를 선언합니다. – SomeJavaGuy
[Oracle Java Tutorials - Exceptions] (https://docs.oracle.com/javase/tutorial/essential/exceptions/)를 참조하십시오. – Jesper