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.

Not getting "Unreachable code" error in: a = true; if (a) { throw; }; console.log(a);

See original GitHub issue

What should happen: CleanShot 2022-01-12 at 10 45 32 What does happen: (no error) CleanShot 2022-01-12 at 10 47 41 I also tried adding as const, still no error: CleanShot 2022-01-12 at 10 44 38

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
RyanCavanaughcommented, Jan 12, 2022

Why are you writing code like this?

1reaction
RyanCavanaughcommented, Jan 12, 2022

I see. Anyway, unreachability errors only occur for syntactically-unreachable positions. We don’t do reachability based on types because it prevents you from writing defensive code

function f(s: string) {
  if (typeof s !== "string") {
    throw new Error("Bad JS caller go away");
    // ^ "unreachable"
  }
  // etc
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: unreachable code after return statement - JavaScript
When an expression exists after a valid return statement, a warning is given to indicate that the code after the return statement is...
Read more >
Throwing temporary exceptions without "unreachable code ...
The problem is I have warnings set as errors, so compilation will fail with a CS0162 Unreachable code detected, since "Some more code"...
Read more >
no-unreachable - ESLint - Pluggable JavaScript Linter
This rule disallows unreachable code after return , throw , continue , and break statements. This rule also flags definitions of instance fields...
Read more >
Unreachable Code Error in Java - GeeksforGeeks
The Unreachable statements refers to statements that won't get executed during the execution of the program are called Unreachable ...
Read more >
unreachable code no-unreachable when throw new error ...
no -unreachable is just a warning that tells you that you have unreachable code in your code. In this case, it is the...
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