https://github.com/hellokitty/easyception
Provides a fluent API for conditional throwing of exceptions.
https://github.com/hellokitty/easyception
Last synced: about 1 year ago
JSON representation
Provides a fluent API for conditional throwing of exceptions.
- Host: GitHub
- URL: https://github.com/hellokitty/easyception
- Owner: HelloKitty
- License: mit
- Created: 2016-07-01T21:14:34.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-03T09:13:37.000Z (almost 10 years ago)
- Last Synced: 2025-03-30T10:23:31.355Z (about 1 year ago)
- Language: C#
- Size: 42 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Easyception
A library that provides a fluent API for managing exceptions with C# 6. (Must have C# 6 to use the API)
## Setup
To use this project you'll first need a couple of things:
- Visual Studio 2015
- C# 6
## How To Use
Using Easyception is easy. The below sections will dicuss how to utilize the Easyception API to manage exceptions in different ways.
##### How to throw
Throwing exceptions using Easyception is done using semantics that feel like an English sentence. The below example will show how to do this using the most basic version of the **Throw** API to throw an InvalidOperationException.
If you are unfamilar with the ?. operator refer to this MSDN article on null-conditionals: https://msdn.microsoft.com/en-us/library/dn986595.aspx
It is absolutely **critical** that you use **?.** for performance reasons. Non-extension version of Now() will throw exceptions when you don't want them if you don't use **?.**
```
using Easyception;
public class Demo
{
public void TestMethod(int val)
{
Throw.If.IsTrue(val < 0)?.Now();
}
}
```
The above example will throw an **InvalidOperationException** if the provided int **val** is negative. There are various other ways to throw using Throw.If. Explore intellisense to get a feeling for the various methods.
But wait! We have **special methods** depending on Throw's type T. Check out the example below that highlights special methods that are only available for certain types of T.
```
using Easyception;
public class Demo
{
public void TestMethod(List obj)
{
Throw.If.IsNull(obj)?.Now();
}
}
```
The above example will throw an **ArgumentNullException** if the provided int **List** is null. This **IsNull* method API is only available if T is ArgumentNullException in Throw. Other exception types have methods like this also so check intellisense for them.
## Builds
Available on a Nuget Feed: https://www.myget.org/F/hellokitty/api/v2 [](https://www.myget.org/)
Offical Nuget: https://www.nuget.org/packages/Easyception/
##Tests
#### Linux/Mono - Unit Tests
||Debug x86|Debug x64|Release x86|Release x64|
|:--:|:--:|:--:|:--:|:--:|:--:|
|**master**| N/A | N/A | N/A | [](https://travis-ci.org/HelloKitty/Easyception) |
|**dev**| N/A | N/A | N/A | [](https://travis-ci.org/HelloKitty/Easyception)|
#### Windows - Unit Tests
(Done locally)
##Licensing
This project is licensed under the MIT license.