Skip to content

ScifaTech/CheckedExceptions

Repository files navigation

CheckedExceptions.NET

Provides an opt-in solution for exceptions management in C# code bases

Build status

Purpose

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.

How to use

  1. Install the Scifa.CheckedExceptions nuget package.
  2. Add the CheckExceptions attribute to your assembly.
  3. Start enjoying enhanced exception management.

Examples

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]

1. Simple throw

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();
}

About

Provides an opt-in solution for exceptions management in C# code bases

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published