Table of Contents

Galaxon.Core.Exceptions

Classes

ArgumentFormatException

This exception type is useful for an ArgumentException that is also a FormatException. The usual FormatException is probably best reserved for situations not involving method parameters, e.g. parsing a file.

I'm using the same parameter order here as used by ArgumentNullException and ArgumentOutOfRangeException. i.e. (paramName, message), for consistency. The base class, ArgumentException, has the parameters in a different order, i.e. (message, paramName), which can be confusing.

For this reason, I've resolved not to use ArgumentException anymore but to treat it as an abstract base class. This will avoid the issue with the arguments being out of order, and the lack of specificity.

Normally for any ArgumentException we want to identify the argument causing the exception (which should be done using nameof()), unless there are several, in which case the offending arguments can be identified in the message.

ArgumentInvalidException

This exception type is useful for an ArgumentException when the argument is invalid for a reason other than being null, out of range, or having an invalid format.

I'm using the same parameter order here as used by ArgumentNullException and ArgumentOutOfRangeException, i.e. (paramName, message), for consistency. The base class, ArgumentException, has the parameters in a different order, i.e. (message, paramName), which can be confusing.

I've resolved not to use ArgumentException anymore but to treat it as an abstract base class. This will avoid the issue with the arguments being out of order, and the lack of specificity.

Normally for any ArgumentException we want to identify the argument causing the exception (which should be done using nameof()), unless there are several, in which case the offending arguments can be identified in the message.

DataNotFoundException

Exception for when an attempt is made to obtain data from a database, but it isn't found. It's a bit more specific than DataException, and sometimes ObjectNotFoundException is not exactly what is meant.

In This Article
Back to top Generated by DocFX | Galaxy logo by Freepik