> For the complete documentation index, see [llms.txt](https://bharat-tiwari.gitbook.io/our-tech-journal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bharat-tiwari.gitbook.io/our-tech-journal/javascript/promise-error-catch-vs-error-function-in-then.md).

# 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'));
```
