Replies: 3 comments 2 replies
-
And while we're waiting... public static class ExceptionExtensions
{
public static void WithData(this Exception e, string key, object value) => e.Data[key] = value;
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
throw new ArgumentException($"Invalid value for {nameof(myParam)}") { Data = { { "value", myParam } }; |
Beta Was this translation helpful? Give feedback.
1 reply
-
You can already use code like the following: throw new ArgumentException($"Invalid value for {nameof(myParam)}") { Data = { ["value"] = myParam } }; While this is more complicated than the suggested |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Exceptions all have a
Data
property, that no one uses. Thats sad. Because there could be additional information about the context of the exception, that doesn't fit in theMessage
property or that should be readable by code and not be parsed from theMessage
.I think part of the problem is that
Data
is hard to set, when throwing anException
.So why not adding a
WithData(string key, object value)
method, to handle this issue like so?Beta Was this translation helpful? Give feedback.
All reactions