question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error handling doesn't work for throw newError() in async function

See original GitHub issue

ok, duplicate issue from nightwatch, becouse i don’t know who could help… how to forward my mistake to ERROR and got false in result?

throw new Error(‘some error’);

(async function () {

try {
let tmp =  await kfs(title);
let staticD = tmp.leads.leadID,
getBoolean = compare(staticD, myStr);

if (getBoolean === false) {

console.log("kfs " + getBoolean);
throw new Error('some error');

}else {      
  console.log(`${'etalon'}`);
}

}catch (err){
console.log(err);
}
}) ()

image

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
IvanNaumenkocommented, Feb 19, 2018

I’ve understood my false. Works!

2reactions
anatoliyarkhipovcommented, Feb 18, 2018

@IvanNaumenko As I can see in the code example from the first post in the thread, you intentionally caught the error and logged it to the console without throwing it further. Have you tried to remove the catch statement from your function? 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Throw Errors From Async Functions in JavaScript?
To recap: Throwing error from an async function won't spit out a "plain exception". Async functions and async methods always return a Promise, ......
Read more >
Error handling with Async/Await in JS | by Ian Segers | ITNEXT
This works as expected, we call the function thisThrows() which throws a regular error, we catch it, log the error and optionally we...
Read more >
Common Mistakes in JavaScript Async Function Error Handling
1. Error thrown from async function is a rejected promise ... For a rejected promise wrapping an uncaught error, we have two options...
Read more >
Error handling with async/await and promises, n² ... - CatchJS
When an error is thrown in an async function, you can catch it with a try ... for catch() has it's own execution...
Read more >
Why can't try/catch handle error throw in Promise constructor
An error inside an async function rejects the promise that the function returns. The Promise constructor doesn't do anything a promise ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found