Frequently we have code such as the below
static int GetSomething()
catch (Exception e)
static void DetermineSpecificExceptionToThrow(Exception exception)
// lot of logic here to determine which exception should be thrown
// This is typically done when you're throwing specific business exceptions
// while this exception is the inner exception
// based upon some information/data in the original exception
The compiler gives an error CS0161. One option is to have the Determine...... method throw exceptions. However, there are time when you don't want to (or can't) do that.
Further the Unit testing code coverage tool doesn't see this correctly (say we did something similar in a switch case statement.
If we could mark a method as one that throws an exception (with an attribute such as [throws]). This would help in both scenarios. Of course the compiler can ensure that all code paths throw an exception in these methods.