CraigChamberlain/SolarLunarDate

Explore handling exceptions.

CraigChamberlain opened this issue · 5 comments

Had problems today raising date not found exception from a system IO exception. If I was using the remote client it would throw an exception on a 404 request.

Need to isolate a solution. Where can I perform tests for valid, year, month.

Consider Code Contracts to push exception handling into the interface of the clients?

Consider TryParse Pattern:
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/exceptions-and-performance
Methods return a bool and if a value is returned by the inner method then it is assigned to an out param provided by the outer method.

Also consider a custom result:
Prefer that greater feedback is provided, for example an enum set as follows.
YearOutOfRnge, MonthOutOfRange, MonthNotAvailableInYear, DayOutOfRange, DayNotAvailableInMonth
With custom error messages for example. Month x only has y days

.Net Code contracts don't seem likely to be supported for .net Core any time soon. I think I need to maintain a version that causes exceptions but can add another. I tend to prefer the idea of having a result type that returns an enum of status and a value. Really miss discriminated unions in f# the Result type would be ideal.

Have implemented custom exceptions in one of the clients in MrBlonde branch, will try and make a set of general unit tests to perform on each client to ensure standarisation. Will look at a SafeParse pattern with custom result type too.

Need to finish writing tests to standardise behaviour between the clients - Particularly on the methods that have try catch GetMonth()... That will do for this branch / version. Would rather use a better pattern, see Beefeater but it will have to be looked at in another issue.