Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] try/catch expressions #23790

Closed
saleyn opened this issue Dec 14, 2017 · 1 comment
Closed

[Proposal] try/catch expressions #23790

saleyn opened this issue Dec 14, 2017 · 1 comment
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue

Comments

@saleyn
Copy link

saleyn commented Dec 14, 2017

I have a feature request to convert try/catch statements to expressions similarly how it's done in C# 7.x. Additionally, when used with code blocks, the last value is returned as the result of the expression:

Example:

  • Current:
string a;
try
{
  a = SomeFunctionThatMightThrow();
}
catch (Exception a)
{
  Print(e);
  a = DefValue;
}
  • Proposed:
var a = try { SomeFunctionThatMightThrow(); } catch (Exception e) { Print(e); DefValue; };
var b = try { SomeFunctionThatMightThrow(); } catch { DefValue };
var c = try   SomeFunctionThatMightThrow()   catch DefValue;
@jcouv
Copy link
Member

jcouv commented Dec 14, 2017

@saleyn Language design discussions have moved over to the csharplang.
What you describe sounds much like dotnet/csharplang#980
I'll go ahead and close this issue as duplicate. Feel free to continue the discussion there.

@jcouv jcouv closed this as completed Dec 14, 2017
@jcouv jcouv added Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue labels Dec 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

2 participants