{"id":15025405,"url":"https://github.com/amantinband/throw","last_synced_at":"2025-05-14T11:12:26.342Z","repository":{"id":38094709,"uuid":"464409464","full_name":"amantinband/throw","owner":"amantinband","description":"A simple, fluent, extensible, and fully customizable library for throwing exceptions for projects using .NET 6+","archived":false,"fork":false,"pushed_at":"2024-08-21T11:15:18.000Z","size":27117,"stargazers_count":1271,"open_issues_count":15,"forks_count":83,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-12T15:31:44.283Z","etag":null,"topics":["argument","assert","assertion","clause","contract","exception","fluent","guard","validation"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amantinband.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-28T09:05:21.000Z","updated_at":"2025-04-29T03:39:39.000Z","dependencies_parsed_at":"2024-09-30T11:00:38.227Z","dependency_job_id":null,"html_url":"https://github.com/amantinband/throw","commit_stats":{"total_commits":62,"total_committers":12,"mean_commits":5.166666666666667,"dds":0.4838709677419355,"last_synced_commit":"719a1cb6dc73de668fad91d19eb68e7efa0477a8"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amantinband%2Fthrow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amantinband%2Fthrow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amantinband%2Fthrow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amantinband%2Fthrow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amantinband","download_url":"https://codeload.github.com/amantinband/throw/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129525,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["argument","assert","assertion","clause","contract","exception","fluent","guard","validation"],"created_at":"2024-09-24T20:02:17.826Z","updated_at":"2025-05-14T11:12:22.626Z","avatar_url":"https://github.com/amantinband.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"assets/icon.png\" alt=\"drawing\" width=\"700px\"/\u003e\n\n[![NuGet](https://img.shields.io/nuget/v/Throw.svg)](https://www.nuget.org/packages/Throw)\n\n[![Build](https://github.com/amantinband/throw/actions/workflows/build.yml/badge.svg)](https://github.com/amantinband/throw/actions/workflows/build.yml) [![publish Throw to NuGet](https://github.com/amantinband/throw/actions/workflows/publish.yml/badge.svg)](https://github.com/amantinband/throw/actions/workflows/publish.yml) [![codecov](https://codecov.io/gh/amantinband/throw/branch/main/graph/badge.svg?token=PA879VKK6M)](https://codecov.io/gh/amantinband/throw)\n\n[![GitHub contributors](https://img.shields.io/github/contributors/amantinband/throw)](https://GitHub.com/amantinband/throw/graphs/contributors/) [![GitHub Stars](https://img.shields.io/github/stars/amantinband/throw.svg)](https://github.com/amantinband/throw/stargazers) [![GitHub license](https://img.shields.io/github/license/amantinband/throw)](https://github.com/amantinband/throw/blob/main/LICENSE)\n\n---\n\n### A simple, fluent, extensible, and fully customizable library for throwing exceptions using .NET 6+\n\n`dotnet add package throw`\n\n![Getting started png](./assets/getting-started.png)\n---\n\n\u003c/div\u003e\n\n- [Give it a star ⭐!](#give-it-a-star-)\n- [Nullable vs non-nullable types](#nullable-vs-non-nullable-types)\n- [Customize everything](#customize-everything)\n  - [How customizing the exception affects the chained rules](#how-customizing-the-exception-affects-the-chained-rules)\n  - [Exception customizations](#exception-customizations)\n    - [1. `Throw()`](#1-throw)\n    - [2. `Throw(\"My custom message\")`](#2-throwmy-custom-message)\n    - [3. `Throw(() =\u003e new MyException())`](#3-throw--new-myexception)\n    - [4. `Throw(paramName =\u003e new MyException($\"Param: {paramName}\")`](#4-throwparamname--new-myexceptionparam-paramname)\n- [Usage](#usage)\n  - [Common types](#common-types)\n    - [Booleans](#booleans)\n    - [Nullable value types (`bool?`, `int?`, `double?`, `DateTime?` etc.)](#nullable-value-types-bool-int-double-datetime-etc)\n    - [Strings](#strings)\n    - [Collections (`IEnumerable`, `IEnumerable\u003cT\u003e`, `ICollection`, `ICollection\u003cT\u003e`, `IList`, etc.)](#collections-ienumerable-ienumerablet-icollection-icollectiont-ilist-etc)\n    - [DateTime](#datetime)\n    - [Enums](#enums)\n    - [Equalities (non-nullables)](#equalities-non-nullables)\n    - [Uris](#uris)\n    - [Comparable (`int`, `double`, `decimal`, `long`, `float`, `short`, `DateTime`, `DateOnly`, `TimeOnly` etc.)](#comparable-int-double-decimal-long-float-short-datetime-dateonly-timeonly-etc)\n    - [Types](#types)\n  - [Nested properties](#nested-properties)\n    - [Boolean properties](#boolean-properties)\n    - [String properties](#string-properties)\n    - [Collection properties](#collection-properties)\n    - [DateTime properties](#datetime-properties)\n    - [Enum properties](#enum-properties)\n    - [property equalities](#property-equalities)\n    - [Uri properties](#uri-properties)\n    - [Comparable properties](#comparable-properties)\n- [Extensibility](#extensibility)\n- [Conditional compilation](#conditional-compilation)\n- [Upcoming features](#upcoming-features)\n- [Contribution](#contribution)\n- [Credits](#credits)\n- [License](#license)\n\n---\n\n# Give it a star ⭐!\n\nLoving it? Show your support by giving this project a star!\n\n# Nullable vs non-nullable types\n\nThis library is designed to work best with [nullable reference types feature](https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references) enabled.\n\nThe `Throw()` method is the entry method for all non-nullable types:\n\n```csharp\nstring name = \"hello\";\nname.Throw().IfLongerThan(10);\n```\n\nAnd `ThrowIfNull()` for any nullable type:\n\n```csharp\nstring? name = \"hello\";\nname.ThrowIfNull();\n```\n\nTrying to use `Throw()` on a nullable type will give a warning\n\n```csharp\nstring? name = null;\nname.Throw() // warning CS8714: The type 'string?' cannot be used as type parameter 'TValue' in the generic type or method 'ValidatableCreationExtensions.Throw\u003cTValue\u003e(TValue, ExceptionCustomizations?, string?)'. Nullability of type argument 'string?' doesn't match 'notnull' constraint.\n    .IfEmpty();\n```\n\nAfter validating that the nullable type isn't null, all the regular non-nullable rules can be used\n\n```csharp\nname.ThrowIfNull()\n    .IfEmpty()\n    .IfLongerThan(3);\n```\n\nThe expression can be implicitly cast to the non-nullable type of the original nullable type\n\n\n```csharp\nstring? name = \"Amichai\";\nstring nonNullableName = name.ThrowIfNull()\n    .IfEmpty()\n    .IfLongerThan(10);\n```\n\nor\n\n```csharp\nint? a = 5;\nint b = a.ThrowIfNull();\n```\n\n# Customize everything\n\n## How customizing the exception affects the chained rules\n\nIf you have customized the exception, any rule that throws an exception will use the customization. For example:\n\n```csharp\n// Default behavior:\nname.Throw()\n    .IfEmpty() // System.ArgumentException: String should not be empty. (Parameter 'name')\n    .IfWhiteSpace() // System.ArgumentException: String should not be white space only. (Parameter 'name')\n    .IfLongerThan(3) // System.ArgumentException: String should not be longer than 3 characters. (Parameter 'name')\n    .IfShorterThan(10); // System.ArgumentException: String should not be shorter than 10 characters. (Parameter 'name')\n\n// Customized behavior:\nname.Throw(paramName =\u003e throw new MyCustomException($\"Param name: {paramName}.\"))\n    .IfEmpty() // MyCustomException: Param name: name.\n    .IfWhiteSpace() // MyCustomException: Param name: name.\n    .IfLongerThan(3) // MyCustomException: Param name: name.\n    .IfShorterThan(10); // MyCustomException: Param name: name.\n```\n\nAt any point, you can change the exception customization, and it will apply for all the rules that follow. For example:\n\n```csharp\nname.Throw(\"String should not be empty or white space only.\")\n        .IfEmpty() // System.ArgumentException: String should not be empty or white space only. (Parameter 'name')\n        .IfWhiteSpace() // System.ArgumentException: String should not be empty or white space only. (Parameter 'name')\n    .Throw(\"String should not be between 3 and 10 characters long.\")\n        .IfLongerThan(3) // System.ArgumentException: String should not be between 3 and 10 characters long. (Parameter 'name')\n        .IfShorterThan(10); // System.ArgumentException: String should not be between 3 and 10 characters long. (Parameter 'name')\n```\n\nTo go back to the default exception, simply use the `Throw()` method. For example:\n\n```csharp\nname.Throw(\"String should not be empty or white space only.\")\n        .IfEmpty() // System.ArgumentException: String should not be empty or white space only. (Parameter 'name')\n        .IfWhiteSpace() // System.ArgumentException: String should not be empty or white space only. (Parameter 'name')\n    .Throw()\n        .IfLongerThan(3) // System.ArgumentException: String should not be longer than 3 characters. (Parameter 'name')\n        .IfShorterThan(10); // System.ArgumentException: String should not be shorter than 10 characters. (Parameter 'name')\n```\n\n## Exception customizations\n\n### 1. `Throw()`\n\nEach rule has a default behavior. If you don't customize the exception, the default behavior will be used.\n\nUse the `Throw()` or `ThrowIfNull()` method to throw the default exception\n\n```csharp\n// ArgumentNullException: Value cannot be null. (Parameter 'nullableValue')\nnullableValue.ThrowIfNull();\n\n// System.ArgumentOutOfRangeException: Value should not be less than 2/28/2042 4:41:46 PM. (Parameter 'dateTime')\\n Actual value was 2/28/2022 4:41:46 PM.\ndateTime.Throw().IfLessThan(DateTime.Now.AddYears(20));\n\n// ArgumentException: Value should not be true (Parameter 'isGood')\nisGood.Throw().IfTrue();\n\n// System.ArgumentException: String should not be empty. (Parameter 'name')\nname.Throw().IfEmpty();\n\n// System.ArgumentOutOfRangeException: Value should not be greater than 0. (Parameter 'number')\\n Actual value was 5.\nnumber.Throw().IfPositive();\n```\n\n### 2. `Throw(\"My custom message\")`\n\nPass a custom exception message to the `Throw()` or `ThrowIfNull()` method\n\n```csharp\n// System.ArgumentNullException: My custom message (Parameter 'nullableValue')\nnullableValue.ThrowIfNull(\"My custom message\");\n\n// System.ArgumentOutOfRangeException: My custom message (Parameter 'dateTime')\\n Actual value was 3/1/2022 10:47:15 AM.\ndateTime.Throw(\"My custom message\").IfLessThan(DateTime.Now.AddYears(20));\n\n// System.ArgumentException: My custom message (Parameter 'isGood')\nisGood.Throw(\"My custom message\").IfTrue();\n\n// System.ArgumentException: My custom message (Parameter 'name')\nname.Throw(\"My custom message\").IfEmpty();\n\n// System.ArgumentOutOfRangeException: My custom message (Parameter 'number')\\n Actual value was 5.\nnumber.Throw(\"My custom message\").IfPositive();\n```\n\n### 3. `Throw(() =\u003e new MyException())`\n\nPass a custom exception thrower to the `Throw()` or `ThrowIfNull()` method\n\n```csharp\n// MyCustomException: Exception of type 'MyCustomException' was thrown.\nnullableValue.ThrowIfNull(() =\u003e throw new MyCustomException());\n\n// MyCustomException: Exception of type 'MyCustomException' was thrown.\ndateTime.Throw(() =\u003e throw new MyCustomException()).IfLessThan(DateTime.Now.AddYears(20));\n\n// MyCustomException: Exception of type 'MyCustomException' was thrown.\nisGood.Throw(() =\u003e throw new MyCustomException()).IfTrue();\n\n// MyCustomException: Exception of type 'MyCustomException' was thrown.\nname.Throw(() =\u003e throw new MyCustomException()).IfEmpty();\n\n// MyCustomException: Exception of type 'MyCustomException' was thrown.\nnumber.Throw(() =\u003e throw new MyCustomException()).IfPositive();\n```\n\n### 4. `Throw(paramName =\u003e new MyException($\"Param: {paramName}\")`\n\nPass a custom exception thrower to the `Throw()` or `ThrowIfNull()` method, that takes the parameter name as a parameter\n\nThis comes in handy in scenarios like this:\n\n```csharp\nvoid SendEmail(User user)\n{\n    user.Throw(paramName =\u003e new UserException(message: \"Cannot send email since user details are invalid.\", paramName: paramName))\n        .IfWhiteSpace(user =\u003e user.FirstName) // UserException: Cannot send email since user details are invalid. (Parameter 'user: user =\u003e user.FirstName')\n        .IfWhiteSpace(user =\u003e user.LastName) // UserException: Cannot send email since user details are invalid. (Parameter 'user: user =\u003e user.LastName')\n        .IfNull(user =\u003e user.Email) // UserException: Cannot send email since user details are invalid. (Parameter 'user: user =\u003e user.Email')\n        .IfLongerThan(user =\u003e user.Email!, 100); // UserException: Cannot send email since user details are invalid. (Parameter 'user: user =\u003e user.Email!')\n\n    emailService.TrySendEmail(user)\n        .Throw(() =\u003e new EmailException(\"Email could not be sent.\"))\n        .IfFalse();\n}\n```\n\n```csharp\n// MyCustomException: Param name: nullableValue.\nnullableValue.ThrowIfNull(paramName =\u003e throw new MyCustomException($\"Param name: {paramName}.\"));\n\n// MyCustomException: Param name: dateTime.\ndateTime.Throw(paramName =\u003e throw new MyCustomException($\"Param name: {paramName}.\")).IfLessThan(DateTime.Now.AddYears(20));\n\n// MyCustomException: Param name: isGood.\nisGood.Throw(paramName =\u003e throw new MyCustomException($\"Param name: {paramName}.\")).IfTrue();\n\n// MyCustomException: Param name: name.\nname.Throw(paramName =\u003e throw new MyCustomException($\"Param name: {paramName}.\")).IfEmpty();\n\n// MyCustomException: Param name: number.\nnumber.Throw(paramName =\u003e throw new MyCustomException($\"Param name: {paramName}.\")).IfPositive();\n```\n\n# Usage\n\n## Common types\n\n### Booleans\n\n```csharp\nvalue.Throw().IfTrue(); // ArgumentException: Value should not be true (Parameter 'value')\nvalue.Throw().IfFalse(); // ArgumentException: Value should be true (Parameter 'value')\n\n// Any method which returns bool can inline it's exception throwing logic.\nEnum.TryParse(\"Unexpected value\", out EmployeeType value)\n    .Throw()\n    .IfFalse(); // System.ArgumentException: Value should be true. (Parameter 'Enum.TryParse(\"Unexpected value\", out EmployeeType value)')\n```\n\n### Nullable value types (`bool?`, `int?`, `double?`, `DateTime?` etc.)\n\n```csharp\nbool? value = null;\n\nvalue.ThrowIfNull(); // ArgumentNullException: Value cannot be null. (Parameter 'value')\n\n// After validating `ThrowIfNull`, any of the regular value type extensions can be used.\nvalue.ThrowIfNull() // ArgumentNullException: Value cannot be null. (Parameter 'value')\n    .IfTrue(); // ArgumentException: Value should not be true (Parameter 'value')\n\n// The returned value from `ThrowIfNull` can be implicitly cast to the original non-nullable type.\nbool nonNullableValue = value.ThrowIfNull(); // ArgumentNullException: Value cannot be null. (Parameter 'value')\n\n```\n\n### Strings\n\n```csharp\nname.Throw().IfEmpty(); // System.ArgumentException: String should not be empty. (Parameter 'name')\nname.Throw().IfWhiteSpace(); // System.ArgumentException: String should not be white space only. (Parameter 'name')\nname.Throw().IfLengthEquals(7); // System.ArgumentException: String length should not be equal to 7. (Parameter 'name')\nname.Throw().IfLengthNotEquals(10); // System.ArgumentException: String length should be equal to 10. (Parameter 'name')\nname.Throw().IfShorterThan(10); // System.ArgumentException: String should not be shorter than 10 characters. (Parameter 'name')\nname.Throw().IfLongerThan(3); // System.ArgumentException: String should not be longer than 3 characters. (Parameter 'name')\nname.Throw().IfEquals(\"Amichai\"); // System.ArgumentException: String should not be equal to 'Amichai' (comparison type: 'Ordinal'). (Parameter 'name')\nname.Throw().IfEquals(\"Amichai\", StringComparison.InvariantCulture); // System.ArgumentException: String should not be equal to 'Amichai' (comparison type: 'InvariantCulture'). (Parameter 'name')\nname.Throw().IfEqualsIgnoreCase(\"AMICHAI\"); // System.ArgumentException: String should not be equal to 'AMICHAI' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'name')\nname.Throw().IfNotEquals(\"Dan\"); // System.ArgumentException: String should be equal to 'Dan' (comparison type: 'Ordinal'). (Parameter 'name')\nname.Throw().IfNotEquals(\"Dan\", StringComparison.InvariantCultureIgnoreCase); // System.ArgumentException: String should be equal to 'Dan' (comparison type: 'InvariantCultureIgnoreCase'). (Parameter 'name')\nname.Throw().IfNotEqualsIgnoreCase(\"Dan\"); // System.ArgumentException: String should be equal to 'Dan' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'name')\nname.Throw().IfContains(\"substring\"); // System.ArgumentException: String should not contain 'substring' (comparison type: 'Ordinal'). (Parameter 'name')\nname.Throw().IfContains(\"substring\", ComparisonType.InvariantCulture); // System.ArgumentException: String should contain 'substring' (comparison type: 'InvariantCulture'). (Parameter 'name')\nname.Throw().IfNotContains(\"substring\"); // System.ArgumentException: String should contain 'substring' (comparison type: 'Ordinal'). (Parameter 'name')\nname.Throw().IfNotContains(\"substring\", ComparisonType.InvariantCultureIgnoreCase); // System.ArgumentException: String should contain 'substring' (comparison type: 'InvariantCultureIgnoreCase'). (Parameter 'name')\nname.Throw().IfStartsWith(\"Jer\"); // System.ArgumentException: String should not start with 'Jer' (comparison type: 'Ordinal'). (Parameter 'name')\nname.Throw().IfStartsWith(\"JER\", StringComparison.OrdinalIgnoreCase); // System.ArgumentException: String should not start with 'JER' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'name')\nname.Throw().IfNotStartsWith(\"dan\"); // System.ArgumentException: String should start with 'dan' (comparison type: 'Ordinal'). (Parameter 'name')\nname.Throw().IfNotStartsWith(\"dan\", StringComparison.InvariantCultureIgnoreCase); // System.ArgumentException: String should start with 'dan' (comparison type: 'InvariantCultureIgnoreCase'). (Parameter 'name')\nname.Throw().IfEndsWith(\"emy\"); // System.ArgumentException: String should not end with 'emy' (comparison type: 'Ordinal'). (Parameter 'name')\nname.Throw().IfEndsWith(\"EMY\", StringComparison.OrdinalIgnoreCase); // System.ArgumentException: String should not end with 'EMY' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'name')\nname.Throw().IfNotEndsWith(\"dan\"); // System.ArgumentException: String should end with 'dan' (comparison type: 'Ordinal'). (Parameter 'name')\nname.Throw().IfNotEndsWith(\"dan\", StringComparison.OrdinalIgnoreCase); // System.ArgumentException: String should end with 'dan' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'name')\nname.Throw().IfMatches(\"J.*y\"); // System.ArgumentException: String should not match RegEx pattern 'J.*y' (Parameter 'name')\nname.Throw().IfMatches(\"[a-z]{0,10}\", RegexOptions.IgnoreCase); // System.ArgumentException: String should not match RegEx pattern '[a-z]{0,10}' (Parameter 'name')\nname.Throw().IfNotMatches(\"^[0-9]+$\"); // System.ArgumentException: String should match RegEx pattern '^[0-9]+$' (Parameter 'name')\nname.Throw().IfNotMatches(\"abc \", RegexOptions.IgnorePatternWhitespace); // System.ArgumentException: String should match RegEx pattern '^[0-9]+$' (Parameter 'name')\n```\n\n### Collections (`IEnumerable`, `IEnumerable\u003cT\u003e`, `ICollection`, `ICollection\u003cT\u003e`, `IList`, etc.)\n\n*Important note: if the collection is a non-evaluated expression, the expression will be evaluated.*\n\n```csharp\ncollection.Throw().IfHasNullElements(); // System.ArgumentException: Collection should not have null elements. (Parameter 'collection')\ncollection.Throw().IfEmpty(); // System.ArgumentException: Collection should not be empty. (Parameter 'collection')\ncollection.Throw().IfNotEmpty(); // System.ArgumentException: Collection should be empty. (Parameter 'collection')\ncollection.Throw().IfCountLessThan(5); // System.ArgumentException: Collection count should not be less than 5. (Parameter 'collection')\ncollection.Throw().IfCountGreaterThan(1); // System.ArgumentException: Collection count should not be greater than 1. (Parameter 'collection')\ncollection.Throw().IfCountEquals(0); // System.ArgumentException: Collection count should not be equal to 0. (Parameter 'collection')\ncollection.Throw().IfCountNotEquals(0); // System.ArgumentException: Collection count should be equal to 0. (Parameter 'collection')\ncollection.Throw().IfContains(\"value\"); // System.ArgumentException: Collection should not contain element. (Parameter 'person: p =\u003e p.Friends')\ncollection.Throw().IfNotContains(\"value\"); // System.ArgumentException: Collection should contain element. (Parameter 'person: p =\u003e p.Friends')\n```\n\n### DateTime\n\n```csharp\ndateTime.Throw().IfUtc(); // System.ArgumentException: Value should not be Utc. (Parameter 'dateTime')\ndateTime.Throw().IfNotUtc(); // System.ArgumentException: Value should be Utc. (Parameter 'dateTime')\ndateTime.Throw().IfDateTimeKind(DateTimeKind.Unspecified); // System.ArgumentException: Value should not be Unspecified. (Parameter 'dateTime')\ndateTime.Throw().IfDateTimeKindNot(DateTimeKind.Local); // System.ArgumentException: Value should be Local. (Parameter 'dateTime')\ndateTime.Throw().IfGreaterThan(DateTime.Now.AddYears(-20)); // System.ArgumentOutOfRangeException: Value should not be greater than 2/28/2002 4:41:19 PM. (Parameter 'dateTime')\ndateTime.Throw().IfLessThan(DateTime.Now.AddYears(20)); // System.ArgumentOutOfRangeException: Value should not be less than 2/28/2042 4:41:46 PM. (Parameter 'dateTime')\ndateTime.Throw().IfEquals(other); // System.ArgumentException: Value should not be equal to 2/28/2022 4:44:39 PM. (Parameter 'dateTime')\n```\n\n### Enums\n\n```csharp\nemployeeType.Throw().IfOutOfRange(); // System.ArgumentOutOfRangeException: Value should be defined in enum. (Parameter 'employeeType')\nemployeeType.Throw().IfEquals(EmployeeType.FullTime); // System.ArgumentException: Value should not be equal to FullTime. (Parameter 'employeeType')\n```\n\n### Equalities (non-nullables)\n\n```csharp\ndateTime.Throw().IfDefault(); // System.ArgumentException: Value should not be default. (Parameter 'dateTime')\ndateTime.Throw().IfNotDefault(); // System.ArgumentException: Value should be default. (Parameter 'dateTime')\nnumber.Throw().IfEquals(5); // System.ArgumentException: Value should not be not be equal to 5. (Parameter 'number')\nnumber.Throw().IfNotEquals(3); // System.ArgumentException: Value should be equal to 3. (Parameter 'number')\n```\n\n### Uris\n\n```csharp\nuri.Throw().IfHttps(); // System.ArgumentException: Uri scheme should not be https. (Parameter 'uri')\nuri.Throw().IfNotHttps(); // System.ArgumentException: Uri scheme should be https. (Parameter 'uri')\nuri.Throw().IfHttp(); // System.ArgumentException: Uri scheme should not be http. (Parameter 'uri')\nuri.Throw().IfNotHttp(); // System.ArgumentException: Uri scheme should be http. (Parameter 'uri')\nuri.Throw().IfScheme(Uri.UriSchemeHttp); // System.ArgumentException: Uri scheme should not be http. (Parameter 'uri')\nuri.Throw().IfSchemeNot(Uri.UriSchemeFtp); // System.ArgumentException: Uri scheme should be ftp. (Parameter 'uri')\nuri.Throw().IfPort(800); // System.ArgumentException: Uri port should not be 80. (Parameter 'uri')\nuri.Throw().IfPortNot(8080); // System.ArgumentException: Uri port should be 8080. (Parameter 'uri')\nuri.Throw().IfAbsolute(); // System.ArgumentException: Uri should be relative. (Parameter 'uri')\nuri.Throw().IfRelative(); // System.ArgumentException: Uri should be absolute. (Parameter 'uri')\nuri.Throw().IfNotAbsolute(); // System.ArgumentException: Uri should be absolute. (Parameter 'uri')\nuri.Throw().IfNotRelative(); // System.ArgumentException: Uri should be relative. (Parameter 'uri')\nuri.Throw().IfHost(\"www.google.com\"); // System.ArgumentException: Uri host should not be www.google.com. (Parameter 'uri')\nuri.Throw().IfHostNot(\"www.google.com\"); // System.ArgumentException: Uri host should be www.google.com. (Parameter 'uri')\n```\n\n### Comparable (`int`, `double`, `decimal`, `long`, `float`, `short`, `DateTime`, `DateOnly`, `TimeOnly` etc.)\n\n```csharp\nnumber.Throw().IfPositive(); // System.ArgumentOutOfRangeException: Value should not be greater than 0. (Parameter 'number')\\n Actual value was 5.\nnumber.Throw().IfNegative(); // System.ArgumentOutOfRangeException: Value should not be less than 0. (Parameter 'number')\\n Actual value was -5.\nnumber.Throw().IfLessThan(10); // System.ArgumentOutOfRangeException: Value should not be less than 10. (Parameter 'number')\\n Actual value was 5.\nnumber.Throw().IfGreaterThan(3); // System.ArgumentOutOfRangeException: Value should not be greater than 3. (Parameter 'number')\\n Actual value was 5.\nnumber.Throw().IfGreaterThanOrEqualTo(5); // System.ArgumentOutOfRangeException: Value should not be greater than or equal to 5. (Parameter 'number')\\n Actual value was 6.\nnumber.Throw().IfLessThanOrEqualTo(5); // System.ArgumentOutOfRangeException: Value should not be less than or equal to 5. (Parameter 'number')\\n Actual value was 4.\nnumber.Throw().IfPositiveOrZero(); // System.ArgumentOutOfRangeException: Value should not be greater than or equal to 0. (Parameter 'number')\\n Actual value was 4.\nnumber.Throw().IfNegativeOrZero(); // System.ArgumentOutOfRangeException: Value should not be less than or equal to 0. (Parameter 'number')\\n Actual value was -1.\nnumber.Throw().IfOutOfRange(0, 5); // System.ArgumentOutOfRangeException: Value should be between 0 and 5. (Parameter 'number')\\n Actual value was -5.\nnumber.Throw().IfInRange(0, 5); // System.ArgumentOutOfRangeException: Value should not be between 0 and 5. (Parameter 'number')\\n Actual value was 4.\n```\n\n### Types\n\n```csharp\nmyObject.Throw().IfType\u003cstring\u003e(); // System.ArgumentException: Parameter should not be of type 'String'. (Parameter 'myObject').\nmyObject.Throw().IfNotType\u003cstring\u003e(); // System.ArgumentException: Parameter should be of type 'String'. (Parameter 'myObject').\n```\n\n## Nested properties\n\n### Boolean properties\n\n```csharp\nperson.Throw().IfTrue(p =\u003e p.IsFunny); // System.ArgumentException: Value should not meet condition (condition: 'person =\u003e person.IsFunny'). (Parameter 'person')\nperson.Throw().IfFalse(p =\u003e p.IsFunny); // System.ArgumentException: Value should meet condition (condition: 'person =\u003e person.IsFunny'). (Parameter 'person')\n\n// We can inline the exception throwing logic with the method call.\nPerson person = GetPerson().Throw().IfTrue(person =\u003e person.Age \u003c 18); // System.ArgumentException: Value should not meet condition (condition: 'person =\u003e person.Age \u003c 18'). (Parameter 'GetPerson()')\n```\n\n### String properties\n\n```csharp\nperson.Throw().IfEmpty(p =\u003e p.Name); // System.ArgumentException: String should not be empty. (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfWhiteSpace(p =\u003e p.Name); // System.ArgumentException: String should not be white space only. (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNullOrWhiteSpace(p =\u003e p.Name); // System.ArgumentException: String should not be null or whitespace. (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNullOrEmpty(p =\u003e p.Name); // System.ArgumentException: String should not be null or empty. (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfLengthEquals(p =\u003e p.Name, 7); // System.ArgumentException: String length should not be equal to 7. (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfLengthNotEquals(p =\u003e p.Name, 10); // System.ArgumentException: String length should be equal to 10. (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfShorterThan(p =\u003e p.Name, 10); // System.ArgumentException: String should not be shorter than 10 characters. (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfLongerThan(p =\u003e p.Name, 3); // System.ArgumentException: String should not be longer than 3 characters. (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfEquals(p =\u003e p.Name, \"Amichai\"); // System.ArgumentException: String should not be equal to 'Amichai' (comparison type: 'Ordinal'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfEquals(p =\u003e p.Name, \"Amichai\", StringComparison.InvariantCulture); // System.ArgumentException: String should not be equal to 'Amichai' (comparison type: 'InvariantCulture'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfEqualsIgnoreCase(p =\u003e p.Name, \"AMICHAI\"); // System.ArgumentException: String should not be equal to 'AMICHAI' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotEquals(p =\u003e p.Name, \"Dan\"); // System.ArgumentException: String should be equal to 'Dan' (comparison type: 'Ordinal'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotEquals(p =\u003e p.Name, \"Dan\", StringComparison.InvariantCultureIgnoreCase); // System.ArgumentException: String should be equal to 'Dan' (comparison type: 'InvariantCultureIgnoreCase'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotEqualsIgnoreCase(p =\u003e p.Name, \"Dan\"); // System.ArgumentException: String should be equal to 'Dan' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfContains(p =\u003e p.Name, \"substring\"); // System.ArgumentException: String should not contain 'substring' (comparison type: 'Ordinal'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfContains(p =\u003e p.Name, \"substring\", ComparisonType.InvariantCulture); // System.ArgumentException: String should contain 'substring' (comparison type: 'InvariantCulture'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotContains(p =\u003e p.Name, \"substring\"); // System.ArgumentException: String should contain 'substring' (comparison type: 'Ordinal'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotContains(p =\u003e p.Name, \"substring\", ComparisonType.InvariantCultureIgnoreCase); // System.ArgumentException: String should contain 'substring' (comparison type: 'InvariantCultureIgnoreCase'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfStartsWith(p =\u003e p.Name, \"Jer\"); // System.ArgumentException: String should not start with 'Jer' (comparison type: 'Ordinal'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfStartsWith(p =\u003e p.Name, \"JER\", StringComparison.OrdinalIgnoreCase); // System.ArgumentException: String should not start with 'JER' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotStartsWith(p =\u003e p.Name, \"dan\"); // System.ArgumentException: String should start with 'dan' (comparison type: 'Ordinal'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotStartsWith(p =\u003e p.Name, \"dan\", StringComparison.InvariantCultureIgnoreCase); // System.ArgumentException: String should start with 'dan' (comparison type: 'InvariantCultureIgnoreCase'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfEndsWith(p =\u003e p.Name, \"emy\"); // System.ArgumentException: String should not end with 'emy' (comparison type: 'Ordinal'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfEndsWith(p =\u003e p.Name, \"EMY\", StringComparison.OrdinalIgnoreCase); // System.ArgumentException: String should not end with 'EMY' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotEndsWith(p =\u003e p.Name, \"dan\"); // System.ArgumentException: String should end with 'dan' (comparison type: 'Ordinal'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotEndsWith(p =\u003e p.Name, \"dan\", StringComparison.OrdinalIgnoreCase); // System.ArgumentException: String should end with 'dan' (comparison type: 'OrdinalIgnoreCase'). (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfMatches(p =\u003e p.Name, \"J.*y\"); // System.ArgumentException: String should not match RegEx pattern 'J.*y' (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfMatches(p =\u003e p.Name, \"[a-z]{0,10}\", RegexOptions.IgnoreCase); // System.ArgumentException: String should not match RegEx pattern '[a-z]{0,10}' (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotMatches(p =\u003e p.Name, \"^[0-9]+$\"); // System.ArgumentException: String should match RegEx pattern '^[0-9]+$' (Parameter 'person: p =\u003e p.Name')\nperson.Throw().IfNotMatches(p =\u003e p.Name, \"abc \", RegexOptions.IgnorePatternWhitespace); // System.ArgumentException: String should match RegEx pattern '^[0-9]+$' (Parameter 'person: p =\u003e p.Name')\n```\n\n### Collection properties\n\n```csharp\nperson.Throw().IfHasNullElements(p =\u003e p.Friends); // System.ArgumentException: Collection should not have null elements. (Parameter 'person: p =\u003e p.Friends')\nperson.Throw().IfEmpty(p =\u003e p.Friends); // System.ArgumentException: Collection should not be empty. (Parameter 'person: p =\u003e p.Friends')\nperson.Throw().IfNotEmpty(p =\u003e p.Friends); // System.ArgumentException: Collection should be empty. (Parameter 'person: p =\u003e p.Friends')\nperson.Throw().IfCountLessThan(p =\u003e p.Friends, 5); // System.ArgumentException: Collection count should not be less than 5. (Parameter 'person: p =\u003e p.Friends')\nperson.Throw().IfCountGreaterThan(p =\u003e p.Friends, 1); // System.ArgumentException: Collection count should not be greater than 1. (Parameter 'person: p =\u003e p.Friends')\nperson.Throw().IfCountEquals(p =\u003e p.Friends, 0); // System.ArgumentException: Collection count should not be equal to 0. (Parameter 'person: p =\u003e p.Friends')\nperson.Throw().IfCountNotEquals(p =\u003e p.Friends, 0); // System.ArgumentException: Collection count should be equal to 0. (Parameter 'person: p =\u003e p.Friends')\nperson.Throw().IfContains(p =\u003e p.Friends, \"Amichai\"); // System.ArgumentException: Collection should not contain element. (Parameter 'person: p =\u003e p.Friends')\nperson.Throw().IfNotContains(p =\u003e p.Friends, \"Amichai\"); // System.ArgumentException: Collection should contain element. (Parameter 'person: p =\u003e p.Friends')\n```\n\n### DateTime properties\n\n```csharp\nperson.Throw().IfUtc(p =\u003e p.DateOfBirth); // System.ArgumentException: Value should not be Utc. (Parameter 'person: p =\u003e p.DateOfBirth')\nperson.Throw().IfNotUtc(p =\u003e p.DateOfBirth); // System.ArgumentException: Value should be Utc. (Parameter 'person: p =\u003e p.DateOfBirth')\nperson.Throw().IfDateTimeKind(p =\u003e p.DateOfBirth, DateTimeKind.Unspecified); // System.ArgumentException: Value should not be Unspecified. (Parameter 'person: p =\u003e p.DateOfBirth')\nperson.Throw().IfDateTimeKindNot(p =\u003e p.DateOfBirth, DateTimeKind.Local); // System.ArgumentException: Value should be Local. (Parameter 'person: p =\u003e p.DateOfBirth')\nperson.Throw().IfGreaterThan(p =\u003e p.DateOfBirth, DateTime.Now.AddYears(-20)); // System.ArgumentOutOfRangeException: Value should not be greater than 2/28/2002 4:41:19 PM. (Parameter 'person: p =\u003e p.DateOfBirth')\nperson.Throw().IfLessThan(p =\u003e p.DateOfBirth, DateTime.Now.AddYears(20)); // System.ArgumentOutOfRangeException: Value should not be less than 2/28/2042 4:41:46 PM. (Parameter 'person: p =\u003e p.DateOfBirth')\nperson.Throw().IfEquals(p =\u003e p.DateOfBirth, other); // System.ArgumentException: Value should not be equal to 2/28/2022 4:45:12 PM. (Parameter 'person: p =\u003e p.DateOfBirth')\n```\n\n### Enum properties\n\n```csharp\nperson.Throw().IfOutOfRange(p =\u003e p.EmployeeType); // System.ArgumentOutOfRangeException: Value should be defined in enum. (Parameter 'person: p =\u003e p.EmployeeType')\nperson.Throw().IfEquals(p =\u003e p.EmployeeType, EmployeeType.FullTime); // System.ArgumentException: Value should not be equal to FullTime. (Parameter 'person: p =\u003e p.EmployeeType')\n```\n\n### property equalities\n\n```csharp\nperson.Throw().IfDefault(p =\u003e p.DateOfBirth); // System.ArgumentException: Value should not be default. (Parameter 'person: p =\u003e p.DateOfBirth')\nperson.Throw().IfNotDefault(p =\u003e p.DateOfBirth); // System.ArgumentException: Value should be default. (Parameter 'person: p =\u003e p.DateOfBirth')\nperson.Throw().IfNull(p =\u003e p.MiddleName); // System.ArgumentNullException: Value cannot be null. (Parameter 'person: p =\u003e p.MiddleName')\nperson.Throw().IfNotNull(p =\u003e p.MiddleName); // System.ArgumentException: Value should be null. (Parameter 'person: p =\u003e p.MiddleName')\nperson.Throw().IfEquals(p =\u003e p.Age, 5); // System.ArgumentException: Value should not be not be equal to 5. (Parameter 'person: p =\u003e p.Age')\nperson.Throw().IfNotEquals(p =\u003e p.Age, 3); // System.ArgumentException: Value should be equal to 3. (Parameter 'person: p =\u003e p.Age')\n```\n\n### Uri properties\n\n```csharp\nperson.Throw().IfHttps(p =\u003e p.Website); // System.ArgumentException: Uri scheme should not be https. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfNotHttps(p =\u003e p.Website); // System.ArgumentException: Uri scheme should be https. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfHttp(p =\u003e p.Website); // System.ArgumentException: Uri scheme should not be http. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfNotHttp(p =\u003e p.Website); // System.ArgumentException: Uri scheme should be http. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfScheme(p =\u003e p.Website, Uri.UriSchemeHttp); // System.ArgumentException: Uri scheme should not be http. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfSchemeNot(p =\u003e p.Website, Uri.UriSchemeFtp); // System.ArgumentException: Uri scheme should be ftp. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfPort(p =\u003e p.Website, 800); // System.ArgumentException: Uri port should not be 80. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfPortNot(p =\u003e p.Website, 8080); // System.ArgumentException: Uri port should be 8080. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfAbsolute(p =\u003e p.Website); // System.ArgumentException: Uri should be relative. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfRelative(p =\u003e p.Website); // System.ArgumentException: Uri should be absolute. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfNotAbsolute(p =\u003e p.Website); // System.ArgumentException: Uri should be absolute. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfNotRelative(p =\u003e p.Website); // System.ArgumentException: Uri should be relative. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfHost(p =\u003e p.Website, \"www.google.com\"); // System.ArgumentException: Uri host should not be www.google.com. (Parameter 'person: p =\u003e p.Website')\nperson.Throw().IfHostNot(p =\u003e p.Website, \"www.google.com\"); // System.ArgumentException: Uri host should be www.google.com. (Parameter 'person: p =\u003e p.Website')\n```\n\n### Comparable properties\n\n```csharp\nperson.Throw().IfPositive(p =\u003e p.Age); // System.ArgumentOutOfRangeException: Value should not be greater than 0. (Parameter 'person: p =\u003e p.Age')\\n Actual value was 5.\nperson.Throw().IfNegative(p =\u003e p.Age); // System.ArgumentOutOfRangeException: Value should not be less than 0. (Parameter 'person: p =\u003e p.Age')\\n Actual value was -5.\nperson.Throw().IfLessThan(p =\u003e p.Age, 10); // System.ArgumentOutOfRangeException: Value should not be less than 10. (Parameter 'person: p =\u003e p.Age')\\n Actual value was 5.\nperson.Throw().IfGreaterThan(p =\u003e p.Age, 3); // System.ArgumentOutOfRangeException: Value should not be greater than 3. (Parameter 'person: p =\u003e p.Age')\\n Actual value was 5.\nperson.Throw().IfGreaterThanOrEqualTo(p =\u003e p.Age, 5); // System.ArgumentOutOfRangeException: Value should not be greater than or equal to 5. (Parameter 'person: p =\u003e p.Age')\\n Actual value was 6.\nperson.Throw().IfLessThanOrEqualTo(p =\u003e p.Age, 5); // System.ArgumentOutOfRangeException: Value should not be less than or equal to 5. (Parameter 'person: p =\u003e p.Age')\\n Actual value was 4.\nperson.Throw().IfPositiveOrZero(p =\u003e p.Age); // System.ArgumentOutOfRangeException: Value should not be greater than or equal to 0. (Parameter 'person: p =\u003e p.Age')\\n Actual value was 4.\nperson.Throw().IfNegativeOrZero(p =\u003e p.Age); // System.ArgumentOutOfRangeException: Value should not be less than or equal to 0. (Parameter 'person: p =\u003e p.Age')\\n Actual value was -1.\nperson.Throw().IfOutOfRange(p =\u003e p.Age, 0, 5); // System.ArgumentOutOfRangeException: Value should be between 0 and 5. (Parameter 'person: p =\u003e p.Age')\\n Actual value was -5.\nperson.Throw().IfInRange(p =\u003e p.Age, 0, 5); // System.ArgumentOutOfRangeException: Value should not be between 0 and 5. (Parameter 'person: p =\u003e p.Age')\\n Actual value was 4.\n```\n\n# Extensibility\n\nYou can easily extend the library by adding your own rules.\n\nHere is a simple example:\n\n```csharp\n\"foo\".Throw().IfFoo(); // System.ArgumentException: String shouldn't equal 'foo' (Parameter '\"foo\"')\n```\n\n```csharp\nnamespace Throw\n{\n    public static class ValidatableExtensions\n    {\n        public static ref readonly Validatable\u003cstring\u003e IfFoo(this in Validatable\u003cstring\u003e validatable)\n        {\n            if (string.Equals(validatable.Value, \"foo\", StringComparison.OrdinalIgnoreCase))\n            {\n                throw new ArgumentException(\"String shouldn't equal 'foo'\", validatable.ParamName);\n            }\n\n            return ref validatable;\n        }\n    }\n}\n```\n\nAnother example:\n\n```csharp\nuser.Throw().IfUsesFacebookOnChrome();\n```\n\n```csharp\nnamespace Throw\n{\n    public static class ValidatableExtensions\n    {\n        public static ref readonly Validatable\u003cUser\u003e IfUsesFacebookOnChrome(this in Validatable\u003cUser\u003e validatable)\n        {\n            if (validatable.Value.FavoriteBrowser == Browser.Chrome \u0026\u0026 validatable.Value.FavoriteWebsite == new Uri(\"https://facebook.com\"))\n            {\n                throw new UserException(\"User shouldn't use Facebook on Chrome!\");\n            }\n\n            return ref validatable;\n        }\n    }\n}\n```\n\nIf you want to use the exception customizations in your extension. You can use the `ExceptionThrower` class which knows how to create the appropriate exception based on the customizations. For example:\n\n```csharp\nnamespace Throw\n{\n    public static class ValidatableExtensions\n    {\n        public static ref readonly Validatable\u003cUser\u003e IfUsesFacebookOnChrome(this in Validatable\u003cUser\u003e validatable)\n        {\n            if (validatable.Value.FavoriteBrowser == Browser.Chrome \u0026\u0026 validatable.Value.FavoriteWebsite == new Uri(\"https://facebook.com\"))\n            {\n                ExceptionThrower.Throw(validatable.ParamName, validatable.ExceptionCustomizations, \"User shouldn't be using Facebook on Chrome.\");\n            }\n\n            return ref validatable;\n        }\n    }\n}\n```\n\nThis will behave as following:\n\n```csharp\nuser.Throw()\n    .IfUsesFacebookOnChrome(); // System.ArgumentException: User shouldn't be using Facebook on Chrome. (Parameter 'user')\n```\n\n```csharp\nuser.Throw(\"A different message.\")\n    .IfUsesFacebookOnChrome(); // System.ArgumentException: A different message. (Parameter 'user')\n```\n\n```csharp\nuser.Throw(() =\u003e new Exception(\"A different exception.\"))\n    .IfUsesFacebookOnChrome(); // System.Exception: A different exception.\n```\n\n```csharp\nuser.Throw(paramName =\u003e new Exception($\"A different exception. Param name: '{paramName}'\"))\n    .IfUsesFacebookOnChrome(); // System.Exception: A different exception. Param name: 'user'\n```\n\n# Conditional compilation\n\nHave a `Throw()` rule that you want to exclude from your release build?\nSimply add `OnlyInDebug()` to the rule and it will be excluded from non-debug builds.\n\n```csharp\n\"foo\".Throw().IfEquals(\"foo\").OnlyInDebug();\n```\n\n```bash\ndotnet run -c Debug # will throw\n```\n\n```bash\ndotnet run -c Release # won't throw\n```\n\n# Upcoming features\n\n- More extension methods: Many more rules to come! Please contribute!\n\n# Contribution\n\nFeel free to open an issue with any idea, bug, or feature request.\n\nWe are trying to be the fastest validation library, so if you have suggestions on improving the runtime speed, share them with us.\n\n\n# Credits\n\n- [Dawn.Guard](https://github.com/safakgur/guard) - An awesome, fast, and intuitive guard clause library for C#. Was a great inspiration for this library.\n\n# License\n\nThis project is licensed under the terms of the [MIT](https://github.com/amantinband/throw/blob/main/LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famantinband%2Fthrow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famantinband%2Fthrow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famantinband%2Fthrow/lists"}