# 에러처리

* try-catch-finally
  * 자바에서 처리하는 방식과 동일하여 별도의 상세한 정리는 하지 않는다.
  * catch 절에서 error 에 관련된 객체를 전달 받을 수 있다.
* 에러 타입
  * 모든 에러는 Error 타입을 상속하여 같은 프로퍼티를 공유한다.
  * 에러 종류
    * Error : 최상위 Error 이며, 커스텀 에러를 만드는데 사용된다.
    * EvalError : eval() 함수를 호출 이외의 용도로 사용시 에러.

      > eval()은 문자열을 코드로 인식하게 하는 함수이다.
    * RangeError : 특정 객체의 범위가 벗어나는 인덱스를 참조 시 발생.
    * ReferenceError : 참조가 불가능 할 때 발생되는 에러.
    * SyntaxError : 문법 에러.
    * TypeError : 타입에 관련된 에러.
    * URIError : encodeURI(), decodeURI()에 옳지 않은 경로를 넘길 시 에러.
* 에러 반환
  * throw 연산자
    * 커스텀 에러를 반환시키며 반드시 값이 필요하고 타입은 제한이 없다.
    * try-catch 외부에서 사용 시 런터임 단계에서 코드의 수행은 멈춘다.
* 커스텀 에러 노하우
  * 자바스크립트는 에러에 대해서 상세한 조건을 제시하지 않는다.
  * 함수가 제대로 실행이 될 수 없는 조건을 인지하고 있다면, 이 조건들을 정리하는 것이 커스텀 에러를 풀어나가는 법이다.
  * 범용적인 함수를 작성시 상세한 정보가 포함된 에러 객체를 반환하도록 해야한다.
  * try-catch 는 브라우저의 기본 방식으로 처리하는 것을 막고 개발자의 의도대로 하기 위함이다.
  * 커스텀 에러는 에러가 일어난 원인을 제공하는 것이 목적이다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://godchiken.gitbook.io/godchiken-dev-story/front/javascript-basic/untitled-8.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
