From 9bfd008fd085b772dc73cdd4337da4e502b29e43 Mon Sep 17 00:00:00 2001 From: zhifenglee-aelf Date: Tue, 8 Oct 2024 11:51:07 +0800 Subject: [PATCH] feat(exception): added aggregated exception from TPL --- AOPExceptionModule/ExceptionHandler.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/AOPExceptionModule/ExceptionHandler.cs b/AOPExceptionModule/ExceptionHandler.cs index 04b2d1f..0772e0b 100644 --- a/AOPExceptionModule/ExceptionHandler.cs +++ b/AOPExceptionModule/ExceptionHandler.cs @@ -22,14 +22,22 @@ private class MethodInfo public override void OnException(MethodExecutionArgs args) { + // If it's an AggregateException, iterate through inner exceptions if (args.Exception is AggregateException aggEx) { foreach (var innerEx in aggEx.InnerExceptions) { - Console.WriteLine($"Inner exception: {innerEx.Message}"); + HandleInnerException(innerEx, args); } } - + else + { + HandleInnerException(args.Exception, args); + } + } + + private void HandleInnerException(Exception exception, MethodExecutionArgs args) + { if(!Exception.IsInstanceOfType(args.Exception)) { return;