# 11.1 Error 객체

* 내장된 Error 객체가 있음
* Error 인스턴스를 만들어서 에러 메시지를 지정할 수 있음
* Error 인스턴스의 역할 : **에러와 통신**

```javascript
  function validateEmail(email) {
    return email.match(/@/) ? email : new Error(`invalid email: ${email}`);
  }

  const email = "jane@doe.com";
  const validatedEmail = validateEmail(email);

  if (validatedEmail instanceof Error) { // Error 인스턴스가 반환됐는지 확인
    console.error(`Error: ${validatedEmail.message}`);
  } else {
    console.log(`Valid email: ${validatedEmail}`);
  }
```


---

# 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://april.gitbook.io/learning-js/chapter-11./11.1-error.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.
