# ExceptionFactory **Repository Path**: lanicon/ExceptionFactory ## Basic Information - **Project Name**: ExceptionFactory - **Description**: Provides a series of factory methods for creating exceptions in .NET - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2020-10-19 - **Last Updated**: 2024-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ExceptionFactory 2.0 ================ [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/scionwest/ExceptionFactory?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) Provides a series of factory methods for creating exceptions in .NET ###2.0 Release Notes This version of the Exception factory contains some breaking changes from the 1.0 source. ExceptionFactory.ThrowExceptionIf(condition == null, "Condition must not be null!"); The above `ThrowExceptionIf` method has been renamed to `ThrowIf` ExceptionFactory.ThrowIf(condition == null, "Condition must not be null!"); The point of the exception factory is to conditionally throw excpetions; having the method titled `ThrowExceptionIf` felt redundant and was thus renamed. ####Conditional chaining You can now chain together more than one exception condition. ExceptionFactory .ThrowIf(condition == null) .Or(() => obj != null) .Or(!(obj is string)); In the above example, the ExceptionFactory will throw a `NullReferenceException` if the `condition` member is null, or the `obj` member is not null. If both of those checks pass, then the last check will throw an `InvalidOperationException` if the `obj` member is not a string. ### Basic conditional Exception throwing ExceptionFactory.ThrowIf(condition == null); ### Basic conditional Exception throwing with custom message ExceptionFactory.ThrowIf(condition == null, "Condition must not be null!"); ### Throw with custom data ExceptionFactory.ThrowIf( condition == null, "Condition must not be null!", new KeyValuePair("Date", DateTime.Now.ToString()); ### Throw Exception from Func ExceptionFactory.ThrowIf( () => !File.Exists("NonExistantFile.txt")); ### Throw Exception from Func with custom Exception Factory delegate ExceptionFactory.ThrowIf( () => !File.Exists(fileName), () => new ArgumentNullException("fileName", "File does not exist.")); ### Throw Exception with callback // Arrange bool testIsPassing = false; // Act ExceptionFactory .Throwif( () => !File.Exists("NonExistantFile.txt")) .ElseDo(() => testIsPassing = true);