question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

catch/rethrow of Exception leads to seemingly inappropriate messages

See original GitHub issue

If 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:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cmeerencommented, Dec 16, 2016

Referring to the OPs list, my (admittedly not that experienced) opinion is this:

(1) Usage of catch-all clauses is not recommended

This should not be shown as long as you re-throw using throw;, which means the exception will continue to propagate upwards.

(2) Exception ‘Exception’ is not documented

This should be shown, since you are, potentially, throwing (or passing on) any type of exception, including System.Expection.

(3) Throwing ‘System.Exception’ is not recommended

This should not be shown, since (correct me if I’m wrong) by using throw; you’re not really throwing Exception, you’re passing on whatever exception comes your way. And if that happens to be System.Exception, then this catch-rethrow block is not where the error is, and thus not where the warning should be shown.

0reactions
cmeerencommented, Dec 16, 2016

For point 1, one could argue that we are not really catching the exception (I think that is your point, right?);

Correct.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found