https://velog.io/@yoonee1126/Day26-%EC%98%88%EC%99%B8%EC%B2%98%EB%A6%AC 보충

| 예외 | 설명 | 예외처리 | 예시 | 발생시점 | 
|---|---|---|---|---|
| checked Exception | 외부영향으로 발생 | 필수 | IOException | 컴파일 시 | 
| runtime Exception | 프로그래머 실수로 발생 | 필수 X | IndexOutOfBoundException, ArithmeticException | 실행 시 | 
public static void nanum(int a, int b) throws ArithmeticException{
	System.out.println(a/b);
}
public static void main(String[] args) {
	int a,b;
	a=100;
	b=0;
	try {
		nanum(a,b);
	} catch(ArithmeticException e) {
		System.out.println(e.getMessage());
		e.printStackTrace();
		System.out.println(e.toString());
	} finally {
		System.out.println("무조건 실행되는 문장");
	}
}



try {
	// 예외가 발생할 가능성이 있는 문장
} catch(Exception e){
	// Exception이 발생했을 때, 이를 처리하기 위한 문장
} catch(Exception2 e){
	// Exception2가 발생했을 때, 이를 처리하기 위한 문장	
}
try {
	System.out.println(1);
    System.out.println(0/10);	// 예외 발생(ArithmeticException). catch문으로 이동
    System.out.println(2);	// 실행되지 않음
} catch(Exception e){	// ArithmeticException가 처리 될 수행문
	System.out.println("예외발생");
}
try{
	...
}catch(Exception1 | Exception2 e){
	e.printStackTrace();
}
try{
	...
} catch(Exception c) {
	...
} finally {
	// 예외가 발생하던 안하던 실행 될 수행문
}
public static void main(String args[]){
	try{
    	throw new Exception("하이");
    } catch (Exception e) {
    	System.out.println(e.getMessage());
    }
}
// 출력값: 하이
public void example(int a) throws Exception{}
public void method1(){
	int a,b;
    a = 10;
    b = 0;
    try {
    	methodA(a,b);
    }catch (ArithmeticException e){
    	System.out.println("처리방법1");
    }
}
public void method2(){
	int a,b;
    a = 0;
    b = 10;
    try{
    	methodA(a,b);
	} catch (ArithmeticException e){
    	System.out.println("처리방법2");
    }
}
public static void methodA(int a, int b) throws ArithmeticException{
	System.out.println(a/b);
}
1. 예외정의
public class CustomException extends Exception{
	CustomException(String message){
    	super(message);	// 예외 객체 생성을 위한 Exception 생성자 호출
    }
}
2. 예외발생
public class Example {
	public static void main(String[] args){
      try {
          String name = "홍길동";
          if(name=="홍길동"){
              throw new CustomException("이미 존재하는 이름입니다.");
          }
      }catch (CustomException e) {
          e.printStackTrace();
      }
    }
}
1. 예외정의
public class CustomException extends Exception{
	CustomException(String message){
    	super(message);
    }
}
2. 예외발생
public class Example{
	public static void main(String[] args) throws CustomException{
      String name="홍길동";
      if(name=="홍길동"){
      	throw new CustomException("이미 존재하는 이름입니다.");
      }
    }
}
https://tedock.tistory.com/80
https://sundrystore.tistory.com/14