gravity00 / simpleexceptionhandling Goto Github PK
View Code? Open in Web Editor NEWLibrary that helps developers to handle exceptions outside catch blocks. Typical usages are global exception handlers.
License: MIT License
Library that helps developers to handle exceptions outside catch blocks. Typical usages are global exception handlers.
License: MIT License
The catch method could also receive an options class as an argument. Example:
var result =
Handling.Prepare()
.Catch(context.Exception, null, new CatchOptions
{
ThrowIfNotHandled = false
});
Allowing the execution of asynchronous handlers for IO intensive operations.
Since the framework replicates the try-catch block, adding a finalization function could be useful, allowing for a try-catch-finally block.
Example to replicate:
try
{
throw new ArgumentNullException();
}
catch (ArgumentNullException)
{
Console.WriteLine("ArgumentNullException thrown");
}
catch (Exception)
{
Console.WriteLine("Exception thrown");
}
finally
{
Console.WriteLine("Finally code executed");
}
At the present moment, the interface IHandlingConfiguration
is responsible for storing handling configurations and running the handling logic itself. This could be considered a violation of the single responsibility principle.
To resolve this question, it could be split, at least, in two interfaces:
IHandlingConfiguration
- stores the collection of handlers and other handling properties;IHandlingService
- contains the logic for handling exceptions, and uses an IHandlingConfiguration
to decide his behavior;This implementation should allow a more decoupled handling logic.
Strong signing the library
The method Handling.Prepare()
is returning an IHandlingConfiguration<object, object>
instead of an IHandlingConfiguration
, as indicated by the documentation.
Example:
IHandlingConfiguration conf = Handling.Prepare(); // error, can´t implicit convert the result
IHandlingConfiguration<object, object> conf = Handling.Prepare(); // success
Make the NuGet package compatible with the new moniker targets. Examples:
Example code:
var result = Handling.Prepare()
.On<ValidationException>(ex =>
{
var messages = new List<string>();
foreach (var error in ex.ValidationErrors)
{
messages.AddRange(error.Messages);
}
context.CreateBadRequestResult(
IsLocalhost(context),
new[]
{
new KeyValuePair<string, string[]>(string.Empty, messages.ToArray())
});
})
.On<BusinessException>(ex =>
{
context.CreateConflictResult(ex.Message, IsLocalhost(context));
})
.On<GenericException>((ex) =>
{
context.TransformResultIntoInternalServerError(ex.Message, IsLocalhost(context));
})
.On<TimeoutException>((ex) =>
{
context.CreateGatewayTimeoutResult(IsLocalhost(context));
})
.On<NotImplementedException>(ex =>
{
context.CreateNotImplementedResult(IsLocalhost(context));
})
.Catch(context.Exception, null, true);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.