# 04. throw expression

Инструкция `throw` используется, чтобы выбросить исключение. Инструкция `throw` имеет следующий синтаксис:

```javascript
throw expression;
throw new Error(message);
```

Результатом выражения `throw` может быть значение любого типа. Инструкции `throw` можно передать число, представляющее код ошибки, или строку, содержащую текст сообщения об ошибке.

```javascript
throw "Error2"; // string
throw 42; // number
throw true; // boolean
throw {
  toString: function() {
    return "I'm an object!";
  }
}; // object
```

Практически любой объект может быть выброшен как исключение. Тем не менее, не все выброшенные объекты создаются равными. Обычно числа или строки выбрасываются как исключения, но часто более эффективным является использование одного из типов исключений, специально созданных для этой цели.


---

# 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://strctr.gitbook.io/programming/01-languages/javascript/01-language/e-controls/e2-exception-handling/04-throw-expression.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.
