Skip to content

Conversation

@sylveon
Copy link
Contributor

@sylveon sylveon commented May 27, 2018

Summary

I feel that quite a lot of uses of the throw; statement can be written in a more clean fashion by using a predicate expression (catch (...) when(condition)), so I've added a note in the try-catch documentation about it.

I feel that quite a lot of uses of the `throw;` statement can be written in a more clean fashion by using a predicate expression (`catch (...) when(condition)`), so I've added a note in the try-catch documentation about it.
@sylveon sylveon requested a review from BillWagner as a code owner May 27, 2018 14:30
@BillWagner BillWagner added the ✨ 1st-time docs contributor! Indicates PRs from new contributors to the docs repository label May 29, 2018
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great addition @sylveon We'd like to publicize the exception filter feature and encourage its use where it creates simpler code.

Over time, I want to update all the samples to show the preferred behavior.

I did have one change request. Can you just push that change to the same branch? Then, I'll :shipit:

Thank you for contributing to docs. 🎆



> [!NOTE]
> It is also possible to use a predicate expression to get a similar result in a often cleaner fashion. The following example has a similar behavior for callers than the precedent example, the function throws the `InvalidCastException` back to the caller when `e.Data` is null.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of "predicate expression", I'd prefer the term "exception filter".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional suggested changes, @sylveon:

  • a often -->an often
  • than the precedent example, --> as the previous example.
  • the function --> The function
  • null --> `null`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the name used a bit before in the same document.

Using catch arguments is one way to filter for the exceptions you
want to handle. You can also use a predicate expression that further
examines the exception to decide whether to handle it. If the
predicate expression returns false, then the search for a handler continues.

Should I change that too while I'm at it @BillWagner?

@rpetrusha will do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @sylveon Yes, let's change it in both locations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and done.

@BillWagner
Copy link
Member

Thanks for making this changes @sylveon

I'll :shipit: now. You should see the changes on the live site in the next day or two.

Thanks again for contributing to docs! 🎆

@BillWagner BillWagner merged commit dff81f5 into dotnet:master May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ 1st-time docs contributor! Indicates PRs from new contributors to the docs repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants