Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to (mis)use Exception.HelpLink to recognize Exception objects?

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.

like image 332
RenniePet Avatar asked Jun 11 '11 02:06

RenniePet


2 Answers

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.

like image 177
Alex Aza Avatar answered Nov 02 '22 23:11

Alex Aza


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. :)

like image 31
The Evil Greebo Avatar answered Nov 02 '22 22:11

The Evil Greebo