자바 의 이상

1073 단어
자바 의 이상
이상 도 대상 입 니 다. 정상 적 인 명령 흐름 을 중단 한 사건 입 니 다. 컴 파일 할 때 문제 가 없고 실행 할 때 문제 가 발생 합 니 다.오류 error, 오류 가 발생 했 습 니 다. JVM 을 직접 닫 습 니 다.Exception 아래 두 개의 하위 클래스, Runtime Exception (실행 시 이상), CheckException (컴 파일 시 이상).
  • 이상 처리 1. try{} catch(){} finally{} 2. 이상 public void SetAge (int age) {if (age < 0) {/ 이상 대상 생 성 Runtime Exception e = new Runtime Exception ("나 이 는 마이너스 일 수 없습니다"); / / 이상 throw e 를 던 집 니 다.}
  • Exception 또는 CheckException 대상 을 던 질 경우 캡 처 또는 성명 을 해 야 한다.
         //      throws    
         public void SetAge(int age) throws Exception{
               if(age < 0){
                    //  Exception    
                    Exception e = new Exception("       ");
                    //    
                    throw e;
               }
         }
    
  • 이상 처리 에 대해 두 가지 방법 이 있 습 니 다. 1. 먼저 성명 하고 호출 할 때 처리 합 니 다.2. 이상 처 리 를 직접 한다.이용 방법 1, 호출 시 처리.class test{ public static void main(String args[]){ User user = new User(); try{ user.setAge(-10); } catch(Exception e){ System.out.println(e); } Finally{}
  • 좋은 웹페이지 즐겨찾기