catch/rethrow of Exception leads to seemingly inappropriate messages
See original GitHub issueIf you catch Exception just to try to do some logging or something, and then rethrow it, you get several messages from Exceptional, none of which seem terribly appropriate in this particular type of usage.
Additionally, and I think more importantly, you can’t suppress them. But I’ll open that up as another ticket.
Example:
public void Blah()
{
try
{
Console.WriteLine("Doing something");
}
catch (Exception e)
{
Console.WriteLine("Oh no! " + e.Message);
throw;
}
That gets:
(1) Usage of catch-all clauses is not recommended (2) Exception ‘Exception’ is not documented (3) Throwing ‘System.Exception’ is not recommended
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Testing the wording of an Exception message
I feel that testing the literal text of an Exception is bad practice. Never try to interpret the wording of an Exception message....
Read more >The case against checked exceptions - Stack Overflow
"Checked exceptions are bad because programmers just abuse them by always catching them and dismissing them which leads to problems being ...
Read more >What happens when an umpire interferes with a catcher's ...
No. Angel Hernandez doesn't throw games to one team or another; his bad calls are unbiased or at least show no discernible pattern...
Read more >pickoff attempt - earned or unearned run?
The rules clearly state that a catcher is not charged with an error on a bad throw when trying to throw out a...
Read more >MLB | WORST CATCHER THROWS! | 1080p HD - YouTube
Although primarily known for having the strongest and most precise throwing arms on the field, catchers are known to make mistakes here and ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Referring to the OPs list, my (admittedly not that experienced) opinion is this:
This should not be shown as long as you re-throw using
throw;
, which means the exception will continue to propagate upwards.This should be shown, since you are, potentially, throwing (or passing on) any type of exception, including
System.Expection
.This should not be shown, since (correct me if I’m wrong) by using
throw;
you’re not really throwingException
, you’re passing on whatever exception comes your way. And if that happens to beSystem.Exception
, then this catch-rethrow block is not where the error is, and thus not where the warning should be shown.Correct.