ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 22-09-08_jsp(4)
    main 2022. 9. 8. 17:46

    다음주가되면.. 아마 다음주 후반부터 db건드리고 그다음주 중급... 그다음엔...filter라는걸 써서 보안을 설정해보고 그러면 401 403 이런거도 볼거라고,...

     

    오늘 cache..어떤 header....와 연결..설정.....

     

    방금전의 flowcontrol이 일단 오늘 수업에서 제일 중요ㅕ함

     

     

    -------------

     

    (https://www.piesocket.com/websocket-tester)

    F12로 네트워크 탭을 열어두자

     

    --------------

    302가 하나있네? redirect한단거져?
    body없음

    개념이해가안되네^^!

     

     

    우리가 어쩃든 모르면 선택을 못한다고 무작위로 하게되니까 알아야 한다고. 

     

     

     

    pending? 계속 연결중이라 연결에 걸리는시간을 못보여준다고?,,,>>>> 끊으면 ms 단윙로바뀜...

    connectless방식...

     

    Http에서 사용되는 하위개념이 websocket

    javascriptㅇ에서도 지원함

    근데 explorer에서는 지원 안함 이페이지에서 실시간 양방향 통신을 못할수있음. 

     

    그런데 해야됨. 웹 표준화에따르면

     

    web socket이 없어도 되어야 함. 

    그때 s?? js 라는거 

    socket io? 라는걸 쓰면 실시간 양방향 채팅을 web socket 없어도 쓸수있음. 

     

     

     

     

    custom exception...어떻게쓰는지...

     

    -----

    throw 가능한 객체의 최상위를 throwable이라고 표현함 여기에 Error계열과 Exception구조 두개가 있으.ㅁ 

     

    Ctrl Shift T 

     

     

    웬만해서는 안생기는 객체, / 에러가 발생했을때 개발자가 의도적으로 try/catch로 처리해버리면 안됨.

    실시간으로 어떻게 할 수 없는게 Error계열

     

    throwable에서 crtl 누르고 open implementation눌러서 ㅗ면 이거저거있는데 exception 보면
    얘는 이럼

     

     

    package kr.or.ddit.exception;
    
    /**
     * 
     * 예외(exception, throwable object)
     *Throwable 최상위 트리구조 형성. 
     *	- Error
     *	- Exception : 비정상적인 상황이되, 직접 처리가 가능한 예외적 상황을 표현하는 객체.
     *		Checked exception : 예외 가능 상황에서 반드시 처리해야 하는 예외, 처리하지 않으면 compile error 발생
     *			ex) IOExcepton, SQLException
     *		unChecked exception : 직접 처리하지 않더라도, 예외 제어권이 메소드 호출구조로 전달되는 예외.
     *			ex) NullPointerException, IllegalArgumentException
     *
     *	처리 방법
     *	직접 처리 : try~catch~finally, try~multi catch, try with resource 
     *	위임 처리 : throws
     *
     */
    
    public class ExceptionDesc {
    
    }

    throws : 나를 호출한 놈에게 예외처리를 떠넘김. 

     

     

     

    객체 하나 만들었는데 바로 에러남, checke exception

     

    public class ExceptionDesc {
    	public static void main(String[] args) throws IOException {
    		method1();
    	}
    	
    	private static void method1() throws IOException {
    		if(1==1)	//unreached 피해가기 위해 의미없는 조건문 하나 넣어주고
    			throw new IOException("강제 발생 예외");
    		System.out.println("method1 호출");
    	}
    }

    이제 이렇게 하면 에러는 VM이 가져감

     

     

    public class ExceptionDesc {
    	public static void main(String[] args){
    		try {
    			method1();
    		} catch (IOException e) {
    			System.err.println(e.getMessage());
    		}
    	}
    	
    	private static void method1() throws IOException {
    		if(1==1)	//unreached 피해가기 위해 의미없는 조건문 하나 넣어주고
    			throw new IOException("강제 발생 예외");
    		System.out.println("method1 호출");
    	}
    }

    이렇게 하면

     

    문제 없는것처럼 조용히 처리할수있지만 이게 정상은 아님

     

     

    public class ExceptionDesc {
    	public static void main(String[] args) throws IOException{
    		try {
    			method1();
    		} catch (IOException e) {
    			System.err.println(e.getMessage());
    			throw e;
    		}
    	}
    	
    	private static void method1() throws IOException {
    		if(1==1)	//unreached 피해가기 위해 의미없는 조건문 하나 넣어주고
    			throw new IOException("강제 발생 예외");
    		System.out.println("method1 호출");
    	}
    }

    이릏게 throw e 해주고 처리해주...

     

     

    ???

     

    이때 사용하는데 unChecked Exception

    public class ExceptionDesc {
    	public static void main(String[] args){
    		try {
    			method1();
    		} catch (IOException e) {
    			System.err.println(e.getMessage());
    			throw new RuntimeException(e);
    		}
    	}
    	
    	private static void method1() throws IOException {
    		if(1==1)	//unreached 피해가기 위해 의미없는 조건문 하나 넣어주고
    			throw new IOException("강제 발생 예외");
    		System.out.println("method1 호출");
    	}
    }

    처리구문을 없애고 사ㅣㅍ을때? 이렇게 예외정보를 바꿀 수 있음..

     

    근데 그렇게 하더라도 원래 예외정보가 사라지면 안 되는게 중요.

     

    두번째줄이찐ㄷ이라고

    ---

    이제 이렇게 하면 되는데,

    32번째 줄의 String text = "23" 을  "a23" 으로 바꾸면 안될거 근데 조용히 처리하고싶을때

     

     

    unchecked 계열..
    38번째 줄 추가하면, 나의 exception 처리과 VM의 예외처리가 같이 동작함..

     

     

    package kr.or.ddit.exception;
    
    import java.io.IOException;
    
    /**
     * 
     * 예외(exception, throwable object)
     *Throwable 최상위 트리구조 형성. 
     *	- Error
     *	- Exception : 비정상적인 상황이되, 직접 처리가 가능한 예외적 상황을 표현하는 객체.
     *		Checked exception : 예외 가능 상황에서 반드시 처리해야 하는 예외, 처리하지 않으면 compile error 발생
     *			ex) IOExcepton, SQLException
     *		unChecked exception : 직접 처리하지 않더라도, 예외 제어권이 메소드 호출구조로 전달되는 예외.
     *			ex) NullPointerException, IllegalArgumentException
     *
     *	처리 방법
     *	직접 처리 : try~catch~finally, try~multi catch, try with resource 
     *	위임 처리 : throws
     *
     */
    
    public class ExceptionDesc {
    	public static void main(String[] args){
    		/*
    		try {
    			method1();
    		} catch (IOException e) {
    			System.err.println(e.getMessage());
    			throw new RuntimeException(e);
    		}
    		 */
    		try {
    			String text = "a23";
    			int number = method2(text);
    			System.out.println(number);
    		} catch (NumberFormatException e) {
    			System.out.println("==============");
    			throw e;
    		}
    	}
    	
    	private static int method2(String text) {
    		try {
    			return Integer.parseInt(text);
    		}catch (RuntimeException e) {
    			
    		}
    	}
    	
    	private static void method1() throws IOException {
    		if(1==1)	//unreached 피해가기 위해 의미없는 조건문 하나 넣어주고
    			throw new IOException("강제 발생 예외");
    		System.out.println("method1 호출");
    	}
    }

    checked 계열의 상위ㅇ는 Exception이고

    unChecked 계열의 상위는 RuntimeException

    근데 tree 구조 따라서 올라가면 RuntimeException위에 Exception이 있음. 

     

     그 얘기는 checke, unchecked 모두 처리를 못하는게 아니라는 얘기임.

    ----

    근데 RuntimeException을 받았다는건..

    여기 왜 에러나냐면 조건문...처럼 처리를 해주어야 한다고?
    return 넣어주면 에러 사라짐 근데 console도 너무 꺠끗해짐

    console에 남겨야 함,. 그래서 쓰는게 e.printStackTrace();

    이런거임.

     

     

    그러면 exception찍히지만 -1도 찍힘. 정상적으로 종료되었다는 뜻임.

     

    음 근데 printStackTrace.... 왜 중간에 stack이있지?

     

    복귀주소..

    A,B,C..B..A... 이렇게 가야 해서... stack이라는 형태로 주소가 저장된다...는....

     

    stack을 tracing해서 보여주는 구조라고....

     그래서 가장 근본적인 에러가 맨 밑에 있는거라고...

     

     

    예외가 발생하면 첫 문장을 먼저 보고, 맨 밑에 문장 보고, 거기서 제일 첫번째 문단 보면 그게 제일 근본적인 문제임. 

     

    ..

     

    ---

    필요에 따라서 나의 예외를 만들어서 쓸 수 도있어야 함., custom exception을 보자

     

     내가 만들고 싶은 예외의 특성에 따라서 상위가 유동적으로 결정되어야 함. 

     

    예외 발생해도 ㄱㅊ 그러면(?)

    runtimeException : 코딩할떄 전혀 신경 안써도 되는게 예외 발생해도 컴파일 에러 안생김

     

    예외 발생하면 critical한 상황이야. 그걸 미연에 방지해야 해 그러면? ==>Checked계열로 만들어야 해서 Exception을 상속받아야 함

     

     

     

    =====

     

     

     

     

    그래ㅔ서...

     

    package kr.or.ddit.exception;
    
    import java.io.IOException;
    
    /**
     * 
     * 예외(exception, throwable object)
     *Throwable 최상위 트리구조 형성. 
     *	- Error
     *	- Exception : 비정상적인 상황이되, 직접 처리가 가능한 예외적 상황을 표현하는 객체.
     *		Checked exception : 예외 가능 상황에서 반드시 처리해야 하는 예외, 처리하지 않으면 compile error 발생
     *			ex) IOExcepton, SQLException
     *		unChecked exception : 직접 처리하지 않더라도, 예외 제어권이 메소드 호출구조로 전달되는 예외.
     *			ex) NullPointerException, IllegalArgumentException
     *
     *	처리 방법
     *	직접 처리 : try~catch~finally, try~multi catch, try with resource 
     *	위임 처리 : throws
     *
     *	Custom Exception 정의
     *
     */
    
    public class ExceptionDesc {
    	public static void main(String[] args){
    		/*
    		try {
    			method1();
    		} catch (IOException e) {
    			System.err.println(e.getMessage());
    			throw new RuntimeException(e);
    		}
    		 */
    		try {
    			String text = "a23";
    			int number = method2(text);
    			System.out.println(number);
    		} catch (NumberFormatException e) {
    			System.out.println("==============");
    			throw e;
    		}
    	}
    	
    	private static int method2(String text) {
    		try {
    			return Integer.parseInt(text);
    		}catch (RuntimeException e) {
    			/*
    			e.printStackTrace();
    			return -1;
    			*/
    			throw new CustomException(e);
    		}
    	}
    	
    	private static void method1() throws IOException {
    		if(1==1)	//unreached 피해가기 위해 의미없는 조건문 하나 넣어주고
    			throw new IOException("강제 발생 예외");
    		System.out.println("method1 호출");
    	}
    }

    ㅇ;렇게 하면

     

    이릏게 에러남... 찐이유를 찾을 수 있는...

     

     

    ---------------

    여기까진 기초였음.. 백을 구성하는 50%였고 다음주부터는 좀 더 효율적으로 할 수 있는 거...

     

    이번주 수업을 마스터를 못하면 다음주 수업은 들어봐야 의미가 없다..

     

    그래서 이번 명절 과제는 없는데요

     

    하나만 부탁할게여 월요일 저녁에 두시간만 오늘이랑 어제 만든 리뷰 다 보고

    수업하자용

    'main' 카테고리의 다른 글

    22-09-13_jsp(2)  (0) 2022.09.13
    22-09-13_python  (0) 2022.09.13
    22-09-08_jsp(3)  (0) 2022.09.08
    22-09-08_jsp(2)  (0) 2022.09.08
    22-09-08_jsp(1)  (2) 2022.09.08
Designed by Tistory.