From aabbfcaf702db122519dbc91d80e0dc0c36a9ab1 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Sun, 28 Nov 2021 22:07:13 +0000 Subject: [PATCH] feat(*): Update readme with exception extensions --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/README.md b/README.md index 83c3142..d26c202 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,69 @@ You can also set SystemTime.Now to any function that returns a DateTime: var startDate = new DateTime(2021, 9, 2); SystemTime.Now = () => startDate.AddDays(2); ``` + +## Exception Extensions + +### BaseExceptionMessage + +Returns a string of the message of the first/root/base exception in an exception stack. + +```csharp +try +{ + ... +} +catch (Exception ex) +{ + string baseExceptionMessage = ex.BaseExceptionMessage(); + ... +} +``` + +### BaseExceptionMessageAndStackTrace + +Returns a single string of the message and stack trace of the first/root/base exception in an exception stack. + +```csharp +try +{ + ... +} +catch (Exception ex) +{ + string baseExceptionMessageAndStackTrace = ex.BaseExceptionMessageAndStackTrace(); + ... +} +``` + +### AllInnerExceptionMessages + +Returns a list of the exception messages of each nested exception in an exception stack. + +```csharp +try +{ + ... +} +catch (Exception ex) +{ + List allInnerExceptionMessages = ex.AllInnerExceptionMessages(); + ... +} +``` + +### AllInnerExceptionMessagesAndStackTraces + +Returns a list of single strings of the message and stack trace of each nested exception in an exception stack. + +```csharp +try +{ + ... +} +catch (Exception ex) +{ + List allInnerExceptionMessagesAndStackTraces = ex.AllInnerExceptionMessagesAndStackTraces(); + ... +} +``` \ No newline at end of file