开发者

Do not understand exception, cant convert to readable text

开发者 https://www.devze.com 2023-01-05 01:22 出处:网络
I have a hash table which stores IPs as strings for the key and an object of my creation in the corresponding value.

I have a hash table which stores IPs as strings for the key and an object of my creation in the corresponding value.

I keep getting an exception at foreach (DictionaryEntry info in MasterHash.Keys). More specifically it happens as the debugger gets to DictionaryEntry. I have tried to provoke a message from my try开发者_StackOverflow catch statement but the compiler does not like me trying to cast e to .ToString or .Message.

private void UpdateMap(Hashtable masterHash)
{
    try
    {
        foreach (DictionaryEntry info in masterHash.Keys)
        {
            AxShockwaveFlashObjects.AxShockwaveFlash axFlash = wfh.Child as AxShockwaveFlashObjects.AxShockwaveFlash;
            IPInstance foo = (IPInstance)info.Value;

            axFlash.CallFunction(foo.GetMarkerCall().ToString(SaveOptions.DisableFormatting));
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.ToString());
    }
}


It might be an invalid cast exception. masterHash.Keys is not a DictionaryEntry. The keys should be strings (your IP string).

EDIT:

ICollection MyKeys = MyTable.Keys;

foreach (object Key in MyKeys)
{
    Console.WriteLine(Key.ToString());
}


I do not know why you are unable to get the values of the exception caught. However, you said that you

stores IPs as strings for the key

but instead you are looping through the keys but expect DictionaryEntry.

Try doing:

foreach(String s in masterHash.Keys)

or something like that instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消