Skip to content

[Good Proposal]™ Expression-bodied try catch like get set #1567

@dangi12012

Description

@dangi12012

This would make Try Catch MUCH less verbose to what it is now:
Since C# 6.0 we can have simple Lambda properties:

string name;
public string Name
{
      get => name;
      set => name = value;
}
public string FullName => $"{FirstName} {LastName}";

It would be VERY cool to have this kind of lambda available for Try Catch:

try => WebClient.DownloadFile(path);
catch(WebException ex) => Log(ex);

EDIT: This example shows the advantage much cleaner. Try the following code with current state of C#:

try
{
      try => Foo();
      catch(BarException) => return null;
}
catch(Exception e) => Log(e.Message);
finally => Free(UnmanagedResource);

If you compare how much boilerplate code was necessary for get;set before C#6.0 you can clearly see how how similar Try Catch is to that. This way code gets less verbose and more readable 👍
What do you think about Expression-bodied try catch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions