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

Added error handling, removed unwanted null check and enhanced readability #7147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ravibaghel
Copy link

The most significant changes include the removal of the null check for "args" in the "Main" method, the addition of a "try-catch" block to handle exceptions during the execution of the "sample" method, and the modification of the final console output line to use string interpolation for better readability.

  1. The null check for "args" in the "Main" method has been removed, indicating that "args" is always expected to be an array, even if it's an empty one. This change simplifies the code and makes the assumption about the nature of "args" more explicit.

  2. A "try-catch" block has been added around the invocation of the "sample" method and the increment of "samples". This change improves the robustness of the code by handling potential exceptions that might occur during the execution of the "sample" method. If an exception is thrown, it is caught and an error message is printed to the console, providing useful information about the error.

  3. The final console output line has been updated to use string interpolation to display the number of samples that ran without any exception. This change enhances the readability of the code by using a more modern and readable way to format strings in C#.

We are excited to review your PR.

So we can do the best job, please check:

  • There's a descriptive title that will make sense to other developers some time from now.
  • There's associated issues. All PR's should have issue(s) associated - unless a trivial self-evident change such as fixing a typo. You can use the format Fixes #nnnn in your description to cause GitHub to automatically close the issue(s) when your PR is merged.
  • Your change description explains what the change does, why you chose your approach, and anything else that reviewers should know.
  • You have included any necessary tests in the same PR.

…r `args` in the `Main` method, the addition of a `try-catch` block to handle exceptions during the execution of the `sample` method, and the modification of the final console output line to use string interpolation for better readability.

1. The null check for `args` in the `Main` method has been removed, indicating that `args` is always expected to be an array, even if it's an empty one. This change simplifies the code and makes the assumption about the nature of `args` more explicit.

2. A `try-catch` block has been added around the invocation of the `sample` method and the increment of `samples`. This change improves the robustness of the code by handling potential exceptions that might occur during the execution of the `sample` method. If an exception is thrown, it is caught and an error message is printed to the console, providing useful information about the error.

3. The final console output line has been updated to use string interpolation to display the number of samples that ran without any exception. This change enhances the readability of the code by using a more modern and readable way to format strings in C#.
@ravibaghel
Copy link
Author

@ravibaghel please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

@ravibaghel
Copy link
Author

ravibaghel commented May 4, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant