marinasundstrom / CheckedExceptions

Enforce better exception handling in C#/.NET by ensuring exceptions are explicitly handled.
MIT License
7 stars 1 forks source link

Refine `THROW001` message #40

Closed marinasundstrom closed 1 week ago

marinasundstrom commented 1 week ago

Currently the THROW001 message is this:

Exception “{0}” is thrown but not handled

It is reported for both throw statements and members.

Problem

The confusion might be in that members (such as methods) are not certain to throw. They might just potentially throw the exceptions reported. So the statement that it "throws" is false.

Idea

This leads us to think; Should the message adapt, or should be a separate error code?

Exception “{0}” is thrown but not handled

Exception “{0}” might be thrown but not handled

Solution

We can control this with parameters to diagnostics:

Exception “{0}” {1} thrown but not handled

With the argument replacing {1} either being "is" or "might be".

Effort

After investigating:

Downside is that we need to fix all tests and make them take that parameter. And that might actually be a benefit in distinguishing the cases between "throw" and methods propagating errors.

marinasundstrom commented 1 week ago

We had to change phrasing in README and other places, like in code comments.

About THROW001:

"Unhandled exception thrown" to "Unhandled exception"