I'm working on a logging program, and I'd like to avoid processing the same Exception
object repeatedly when it is being logged repeatedly because it is percolating up through a nested call structure. So I'd like to be able to format the Exception
object once, and give the formatted version a unique "exception number" and then tag the Exception
object somehow so I can recognize it if it turns up again in a later log call.
The idea I've come up with is to misuse the HelpLink
field of the Exception
object. I'll set it to contain a string version of my "exception number". Then I can recognize the Exception
object if it shows up again momentarily in another log call.
But is this maybe a bad idea? Are there any gotchas involved that I haven't thought of? If so, does anyone have a better idea?
EDIT: To explain the situation a bit more, this logger will only be used on my own programs.
Instead of 'abusing' HelpLink
property, you could use Data
property to add extra information to the Exception
. It contains key/value pairs that provide additional user-defined information about the exception.
While I agree with TheVillageIdiot, I would point out that more generally speaking, if you want to change the behavior of Exception, then you should create your own Exception class that add's additional pertinent information. That's why we use inheritance and polymorphism, after all. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With