Loading Gist 9b19bd51efc24578916f...
The antidote is to wrap the primitive in a Whole Value. It's a pretty straightforward transformation when your code looks like this:
- Make a new exception class, typically nested at the current scope.
- Name it based on the message text.
- Parameters to the message become parameters to the constructor and properties on the new class.
- Override the "Message" property to hold the string.Format() call.
Loading Gist cab0b9d0d41cc49024ab...Like all good design moves, this helps testing.
Loading Gist 540936ec75b8b9585188...
Note that in the 2nd example, I'm separating "I expect this exception with these properties" from "the exception should be able to format itself like this". There's a nice separation of concerns.