# Promise Error: Catch vs Error Function in Then

<https://stackoverflow.com/a/33278420>

```javascript
somePromise.then(() => {
   // if some error happens here, it will be caught in 'catch'
   anErrorThrowingFunction('some wrong param');
}).catch((err) => console.log('Errror occured'));

// below will yield similar result as above, the errorHandler tries to catch any unhandled error
// from previous result.
somePromise.then(() => {
   // if some error happens here, it will be caught in 'catch'
   anErrorThrowingFunction('some wrong param');
}).then(null, errorHandler);



/// in below example, the error in Success function of then won't be caught
somePromise.then(() => {
   // if some error happens here, it will be caught in 'catch'
   anErrorThrowingFunction('some wrong param');
}, (err) => console.log('error'));
```


---

# 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://bharat-tiwari.gitbook.io/our-tech-journal/javascript/promise-error-catch-vs-error-function-in-then.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.
