본문 바로가기
JAVA/javascript, jQuery

자바스크립트 - try-catch

by 설총이 2018. 7. 3.

catch 블록

catch 블록은

throw문장에 의해 명시된 값을 가지고 있는 식별자(앞 구문의 catchID)를 명시합니다

이 식별자를 발생된 예외에 대한 정보를 얻기 위하여 사용할 수 있습니다. 자바스크립트는 catch 블록에 진입했을때 식별자를 생성합니다; 식별자는 catch 블록에 있는 동안만 유지됩니다; catch 블록의 시행이 끝난 후, 식별자는 더이상 사용하실 수 없습니다.


*try-catch에서 에러 메서드


error.description : undefined

error.name : reference error

error.message : allert not defined



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script>
    var msg = "";
    function test(){
        try{
            allert("hello world!");
        }
        catch(error){
            msg = "다음과 같은 오류가 발생하였음 : " + error.message;
            alert(msg);
        //error.description : undefined
        //error.name : reference error
        //error.message : allert not defined
        }
    }
</script>
cs