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.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on JJ.Framework.Exceptions:

Package Downloads
JJ.Framework.IO
CsvReader FileLock PathParser SafeFileOverwriter GetNumberedFilePath StreamToBytes BytesToStream StreamToString StringToStream StringToBytes BytesToString ReadStruct WriteStruct ClearFolder ClearFolderRecursive GetFolderSize GetFolderSizeRecursive CountFilesRecursive IsFolder IsFile FolderIsEmpty IsReadOnly IsHidden MakeReadOnly MakeWritable ShowFile HideFile ToAbsolutePath ToRelativePath PathsAreEqual AssertFileExists
JJ.Framework.Collections
LINQ overloads. SelectRecursive SelectAncestors Add Remove AddRange Concat CrossJoin Distinct DistinctMany Except FirstWithClearException SingleOrDefaultWithClearException SingleWithClearException ForEach IndexOf TryGetIndexOf MinOrDefault MaxOrDefault PeekOrDefault PopOrDefault Product RemoveFirst Repeat ToHashSet ToNonUniqueDictionary TrimAll TryRemoveFirst Union Zip item.AsArray item.AsList item.AsEnumerable. Also a RedBlackTree and KeyValuePairHelper ConvertNamesAndValuesListToKeyValuePairs and ConvertNamesAndValuesListToDictionary.
JJ.Framework.Testing
Helper for unit tests. Mimics the Assert class, but will display the tested expression in error messages, instead of being vague about it or laborious to program. It also offers methods to evaluate if the right exception goes off in the right spot with the right exception type and / or the right message.
JJ.Framework.Mathematics
Interpolator Smooth Bezier Cubic Hermite TextPlotter NumberBases ToBase FromBase ToHex FromHex ToLetterSequence FromLetterSequence Randomizer GetRandomItem GetInt32 GetDouble GetSingle IsInRectangle GetCenter AbsoluteDistance IsPowerOf2 LogRatio RoundToSignificantDigits RoundWithStep ScaleLinearly SpeadItems SpreadIntegers SpreadDoubles. Integer variation of Pow and Log.
JJ.Framework.Xml
XmlToObjectConverter converts an XmlDocument or string to an object graph. The way to map XML to classes is easier than the classic ways in .NET. XmlHelper allows you to access XML in a null-safe and multiplicity-safe way. It uses XmlDocument as the underlying .NET API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.5.6877.41327 950 10/31/2018
1.4.6873.32508 203 10/26/2018
1.4.6873.32106 203 10/26/2018
1.4.6862.40443 565 10/15/2018
1.3.6681.33422 717 4/17/2018
1.2.6640.39175 313 3/7/2018
1.1.0.31224 383 3/4/2018
1.0.6636.31311 358 3/3/2018
1.0.6636.153 384 3/2/2018