Skip to content

Commit

Permalink
feat(readme): updated readme with usage
Browse files Browse the repository at this point in the history
  • Loading branch information
zhifenglee-aelf committed Oct 14, 2024
1 parent eae5a0a commit cc8b52e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ A demo of AOP Exception Handling.
- [Logging](#logging)
- [Message](#message)
- [Return Value](#return-value)
- [Logging Method Parameters](#logging-method-parameters)
- [Return Type Exception](#return-type-exception)
- [Limitations](#limitations)
- [Examples](#examples)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -141,6 +144,16 @@ public async Task<FlowBehavior> HandleException(Exception ex, string message)
}
}
```
4. Continue: The method will continue to the next exception specified or rethrow if there are no other exceptions.
```csharp
public async Task<FlowBehavior> HandleException(Exception ex, string message)
{
return new FlowBehavior
{
ExceptionHandlingStrategy = ExceptionHandlingStrategy.Continue
}
}
```

### Multiple Exception Handling
You can stack multiple ExceptionHandler attributes on a method to handle multiple exceptions.
Expand Down Expand Up @@ -254,6 +267,31 @@ The ReturnDefault property can be set to the following:
2. Default: Returns the default value of the return type (i.e. default(T)).
3. None: Indicates not to use the ReturnDefault property.

### Logging Method Parameters

You may log the method parameters by specifying through the `LogTargets`. For example:
```csharp
[ExceptionHandler(typeof(Exception),
ReturnDefault = ReturnDefault.Default,
LogTargets = ["i", "dummy"])]
protected virtual async Task<decimal> Boo(int i, Dummy dummy, string name = "some name")
{
throw new Exception("boo!");
return 10;
}
```
The above will log the values of i and dummy when the exception is thrown.

### Return Type Exception

The program will throw a `ReturnTypeMismatchException` when the return type specified in your `FlowBehavior.ReturnValue` is not the corresponding return type to the method that has thrown.

## Limitations
1. The method must return a Task.
2. The method must be virtual or abstract.
3. Unit Test class methods are not supported.
4. `internal` methods are not supported.

## Examples

Example with multiple exception handler:
Expand Down

0 comments on commit cc8b52e

Please sign in to comment.