lundi 6 juillet 2015

When does the MethodHandle of an Exception change?

I'm trying to see if I can group exceptions together in some legacy code. I have a Logger class that accepts the exception and log's it. Ideally I want some kind of unique identifier (regardless of the text) of where an exception was thrown.

I stumbled upon the Exception.TargetSite.MethodHandle. This appeared to be a integer that I could use to do just what I wanted. In debug I fired an exception multiple times and noticed that the values appeared static, great!

enter image description here

So I moved the exception to confirm that it'd alter if the exception was different, the value changed, also great!

I put the exception back to where is was originally and tested again, expecting the original integer value to be returned, but it wasn't, it returned a totally different value. :(

It appears that the values changes everytime I recompile the source.

This leads me to my question. The docs on MethodHandle are not great:

Gets a handle to the internal metadata representation of a method.

Thanks Microsoft very informative. I'm presuming that the MethodHandle is some kind of address in memory for the method? Though I'm not sure. Can anyone explain when and why this value changes? Is it stamped in the assembly or is it a memory address on the stack or heap? Will it change when the process recycles?





Aucun commentaire:

Enregistrer un commentaire