-
Notifications
You must be signed in to change notification settings - Fork 4
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
🩹 [Patch]: Remove unnecessary try..catch blocks #289
Comments
Feel free to suggest a good way to implement error reporting on the top level functions! |
This is a heavily debated topic. My 2 cents: Less is more. I have tried a few approaches to capturing and repackaging errors and none have proven as resilient and pain free as avoiding When I use a try..catch block, it is usually in a common function (like Invoke-GitHubAPI) and generally looks like this: try {
# Do something
}
catch {
# Optionally log the Exception. DO NOT alter it but DO add more details if useful.
if ([something I can ignore or work around]) {
# Do that
}
else {
throw # re-throw the original exception
}
} I also often use I fully advocate the notion of leading people to the pit of success. |
Describe the change
I'm seeing this anti-pattern a lot in your code.
If you aren't going to do anything with the caught exception there is no benefit to catching it. It adds unnecessary runtime overhead, and adversely affects readability.
Also, if you are going to re-throw the original exception it is better to just
throw
.throw $_
adds unnecessary overhead.The text was updated successfully, but these errors were encountered: