JJ.Framework.Exceptions 1.5.6877.41327

Contains many exception classes for common basic errors. Clear messages, concise syntax, strongly-typed, good performance. Generates messages like "myParent.MyChildren[0].MyProperty is null.", "height of 2 is less than 10.", "Customer with key { customerNumber = 1234, customerType = Subscriber } not found."

Install-Package JJ.Framework.Exceptions -Version 1.5.6877.41327
dotnet add package JJ.Framework.Exceptions --version 1.5.6877.41327
<PackageReference Include="JJ.Framework.Exceptions" Version="1.5.6877.41327" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JJ.Framework.Exceptions --version 1.5.6877.41327
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

JJ.Framework.Exceptions

Contains many exception classes for common basic errors, for instance:

  • Null errors, null or white space errors, collection contains nulls, etc.
  • Parsing errors, type casting errors
  • Not found, not unique errors
  • Greater than or equal errors and the like
  • Files not found, folder already exists, etc.

There are several advantages over using these exception types.

  • Error messages are clear.
  • Concise syntax, without sacrificing performance.
  • You can pass an expression, whose text becomes part of the message.
  • Invalid value is automatically mentioned in the exception message.
  • Lose no time typing and trying to come up with a good message.

For example:

throw new NullException(() => myParent.MyChildren[0].MyProperty);

Will produce an exception message:

"myParent.MyChildren[0].MyProperty is null."

This is where it surpasses the possibilities of the C# 6 nameof operator, which can only mention a name, not a whole expression.

Another example:

throw new NotFoundException<Customer>(new { customerNumber, customerType });

will produce an exception message:

"Customer with key { customerNumber = 1234, customerType = Subscriber } not found."

As such it is fit for use with any composite key you might have.

Some more examples:

throw new NotUniqueException<Product>(productNumber);
throw new ValueNotSupportedException(myCountryEnumValue);
throw new FileAlreadyExistsException("text.txt");
throw new NullOrWhiteSpaceException(nameof(myParam));

Those produce the exception messages:

Product with key A123 not unique.
Country value 'Undefined' is not supported.
File 'test.txt' already exists.
myParam is null or white space.

Here is an example with the value check in it:

if (height < 10) throw new LessThanException(() => height, 10);

This produces the exception message:

height of 2 is less than 10.

JJ.Framework.Exceptions

Contains many exception classes for common basic errors, for instance:

  • Null errors, null or white space errors, collection contains nulls, etc.
  • Parsing errors, type casting errors
  • Not found, not unique errors
  • Greater than or equal errors and the like
  • Files not found, folder already exists, etc.

There are several advantages over using these exception types.

  • Error messages are clear.
  • Concise syntax, without sacrificing performance.
  • You can pass an expression, whose text becomes part of the message.
  • Invalid value is automatically mentioned in the exception message.
  • Lose no time typing and trying to come up with a good message.

For example:

throw new NullException(() => myParent.MyChildren[0].MyProperty);

Will produce an exception message:

"myParent.MyChildren[0].MyProperty is null."

This is where it surpasses the possibilities of the C# 6 nameof operator, which can only mention a name, not a whole expression.

Another example:

throw new NotFoundException<Customer>(new { customerNumber, customerType });

will produce an exception message:

"Customer with key { customerNumber = 1234, customerType = Subscriber } not found."

As such it is fit for use with any composite key you might have.

Some more examples:

throw new NotUniqueException<Product>(productNumber);
throw new ValueNotSupportedException(myCountryEnumValue);
throw new FileAlreadyExistsException("text.txt");
throw new NullOrWhiteSpaceException(nameof(myParam));

Those produce the exception messages:

Product with key A123 not unique.
Country value 'Undefined' is not supported.
File 'test.txt' already exists.
myParam is null or white space.

Here is an example with the value check in it:

if (height < 10) throw new LessThanException(() => height, 10);

This produces the exception message:

height of 2 is less than 10.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.5.6877.41327 586 10/31/2018
1.4.6873.32508 125 10/26/2018
1.4.6873.32106 120 10/26/2018
1.4.6862.40443 262 10/15/2018
1.3.6681.33422 564 4/17/2018
1.2.6640.39175 196 3/7/2018
1.1.0.31224 238 3/4/2018
1.0.6636.31311 251 3/3/2018
1.0.6636.153 259 3/2/2018