Provides an opt-in solution for exceptions management in C# code bases
Early in the development of C# the design team chose not to include checked exceptions in the language. This was decided because they could not find a solution they felt would be appropriate.
Java has for many years had checked exception but much java code ends up abusing it by appending throws Exception to the end of most methods.
This library tries to provide a middle-ground where exceptions can be managed and controlled in critical assemblies whilst not
burdening the developers of other assemblies with managing their exceptions.
- Install the Scifa.CheckedExceptions nuget package.
- Add the
CheckExceptionsattribute to your assembly. - Start enjoying enhanced exception management.
Somewhere in your assembly, you must specify the CheckExceptions attribute. All examples that follow assume that this attribute is set.
using Scifa.CheckedExceptions.Attributes;
[assembly: CheckExceptions]The following code will show an error on the throw line.
public void Leaks_NotImplementedException()
{
throw new NotImplementedException();
}to fix this error, add a Throws attribute:
[Throws(typeof(NotImplementedException))]
public void Leaks_NotImplementedException()
{
throw new NotImplementedException();
}