JPolicy 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package JPolicy --version 1.0.0                
NuGet\Install-Package JPolicy -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JPolicy" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JPolicy --version 1.0.0                
#r "nuget: JPolicy, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JPolicy as a Cake Addin
#addin nuget:?package=JPolicy&version=1.0.0

// Install JPolicy as a Cake Tool
#tool nuget:?package=JPolicy&version=1.0.0                

JPolicy

JPolicy is a dynamic error exception handler. It will allow method execuction without wrapping in the try catch.
It also includes definition of policies, just like to retry method execution when failed,
default error message display during the exception, and method to execute to get the verbose exception to display or for logging purposes.

Requirements

  • .NET Core 3.1
  • Visual Studio or VS Code

How to use:

  • Go to Tools and select Manage Nuget Packages and Search for JPolicy library
    Install-Package JPolicy -Version 1.0.0

Sample Code:

using System;
using System.Collections.Generic;

namespace JPolicy.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();

            p.JWithMultiplePolicies();

            p.JDefaultPolicy();
        }

        private void JWithMultiplePolicies()
        {
            int retryExecute = 2;

            string defaultErrorMsg = "Opps! An error occured";

            bool throwException = false;

            JPolicy.CreatePolicy(retryExecute, defaultErrorMsg, test => DisplayException(test), throwException)
                                   .Execute(context => throw new Exception("I'm Inevitable"),
                                   new Dictionary<string, object>() { { "InErrorMessage", $"name of the method/function {nameof(Program)}" } });
        }

        public void JDefaultPolicy()
        {
            JPolicy.CreatePolicy().Execute(context => throw new Exception("I'm Inevitable"),
                                    new Dictionary<string, object>() { { "InErrorMessage", $"name of the method/function {nameof(Program)}" } });

        }

        private static void DisplayException(object message)
        {
            Console.WriteLine(message);
        }
    }
}

License

License: MIT
Copyright (c) 2020 Joever Monceda

Linkedin: Joever Monceda
Medium: Joever Monceda
Twitter @_EthanHunt07
Facebook: Ethan Hunt

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 394 5/17/2021
1.0.0 366 11/25/2020