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.

Support 'throw' expressions

See original GitHub issue

Support proposal-throw-expressions.
That proposal is now stage-1, but worth to implements for convenience and this proposal not break backward-compatibilities.

Current

ts

const errorThrowExp = () => { throw new Error('Error!'); }
function errorThrowFn(maybeTrue) {
  if (maybeTrue){ 
    return ...;
  } else {
    throw new Error('Error!');
  }
}

js

const errorThrowExp = function() {throw new Error('Error!')}
function errorThrowFn(maybeTrue) {
  if (maybeTrue){ 
    return ...;
  } else {
    throw new Error('Error!');
  }
}

Proposal

ts

const errorThrower = () => throw new Error('Error!');
function errorThrowFn(maybeTrue: boolean) {
  return maybeTrue? ...: throw new Error('Error!');
}

js

const errorThrower = function() { throw new Error('Error!'); }
function errorThrowFn(maybeTrue: boolean) {
  return maybeTrue? ...: (function() { throw new Error('Error!') })();
}

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
rbucktoncommented, Sep 18, 2017

https://github.com/Microsoft/TypeScript/tree/throwOperator?files=1

Currently it does not yet support unreachability checks at the expression level. Also, I am waiting for the next TC39 meeting to see if the proposal moves to Stage 2.

2reactions
DanielRosenwassercommented, Sep 17, 2017

So is this proposal premature?

Nope, it’s fine to track it here. Like @kitsonk said, @rbuckton is championing it and is part of our team, but we will need it to reach a later stage before adopting it in TypeScript.

For what it’s worth, I’d be willing to bet he has a branch with an implementation of throw-expressions. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/plugin-syntax-throw-expressions
Syntax only. It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax.
Read more >
C# 7.0 and 7.1 support in ReSharper – Throw expressions
Throw expressions allow us to throw exceptions from almost any expression, making our code more concise and readable. ReSharper adds inspections ...
Read more >
@babel/plugin-syntax-throw-expressions - npm
Allow parsing of Throw Expressions. Latest version: 7.18.6, last published: 6 months ago. Start using @babel/plugin-syntax-throw-expressions ...
Read more >
Using throw expressions - C# 7.0 - Gunnar Peipman
Throw expressions are here to help us write smaller code and use exceptions in expression-bodied members. It is just a language feature and...
Read more >
throw expression - cppreference.com
throw expression ... Concurrency support library (C++11) ... 1) First, copy-initializes the exception object from expression ...
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