예외를 던지는 방법은 더 직접적입니다.
if (age <0) {Throw New MyException ( "나이가 없어 질 수 없습니다!");} 예를 살펴 보겠습니다.
패키지 테스트; public class test {public static void main (string s = "abc") {wash numberformatexception (); println (s); 작업 결과는 다음과 같습니다.
Java에서는 메소드가 정의 될 때 예외를 선언 할 수 있으며, 예외를 던지면 구현 중에 구체적으로 던질 수 있습니다.
ppublic class shoot {클래스 생성 정적 void pop () 만들기 부 ) {// main method try {pop (); call} catch (negativearraysizeexception e) {system.out.println; }}}