# Errors

```
new Error([message[, fileName[, lineNumber]]])
```

* Filename and LineNumber default
* .name is Error default but there are [more](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)&#x20;
* .stack is call stack that most envs give

*New and just `Error` are same*

## Usage

```javascript
try {
  throw new Error("Parameter is not a number!");
  //throw new Error([message[, fileName[, lineNumber]]])
}
catch(err) {
    alert(e.message); // This is an error
} finally { //can just have the finally if you dont want to catch error?
  //do something regardless of result
}
```

Error has name, message and can have custom info/code

*could technically throw and catch anything*

## Custom Errors

```javascript
export class MediaError extends Error {
  //without constructor will include this class in stack trace
  constructor(message, user_message, err) {
    super(message);
    this.name = "MediaError";
    this.user_message = user_message;
    if (Error.captureStackTrace !== undefined) {
      //Firefox problem, since its non-standard
      Error.captureStackTrace(this, MediaError);
    }
  }
}
```

### Common Custom Errors

#### Axios

err.response

### HTTP

Check out http-errors Node package or HTTP Fundamentals


---

# 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://openai.gitbook.io/code-cheatsheets/js/errors.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.
