Ronny
Ronny

Reputation: 4537

How can I catch JS exceptions from async functions I don't control?

I know using try..catch for async functions doesn't work, and most advice I've read suggests using it inside the passed callback.

However, without control over the async function which throws the exception, what can one do to catch it? In my example it's chrome.bookmarks.create, which fails on some edge cases.

Upvotes: 0

Views: 242

Answers (2)

Rob W
Rob W

Reputation: 349032

In Chrome extensions, there are two possible ways of catching asynchronous errors:

Upvotes: 1

cvsguimaraes
cvsguimaraes

Reputation: 13240

In general cases there's no way to catch exceptions on third party functions, you'll have to use error handling methods provided by someone else.

In case of Chrome's extension API you have the lastError property. Enjoy.

Upvotes: 0

Related Questions