开发者

Exception handling internal bug

开发者 https://www.devze.com 2023-02-17 22:26 出处:网络
Code: public static void Test() { try { OpenConnectionToDatabase(); //Opens a connection to Oracle DB } catch(Exception e)

Code:

public static void Test()
{
   try
   {
       OpenConnectionToDatabase(); //Opens a connection to Oracle DB

   } catch(Exception e)
   {
       e.Data.Add("Query:", command.CommandText);
       throw e;
   }
}

Wh开发者_如何学编程en this code is executed when the Database server is being shutdown and the communication is disrupted, .NET throws the following error: Item has already been added. Key in dictionary: 'Query:' Key being added: 'Query:' at System.Collections.ListDictionaryInternal.Add(Object key, Object value)

How can this be?


EDIT: (based on @LukeH's comment)

e.Data["Query:"] = command.CommandText;


Don't use "throw e;". Just use throw.

0

精彩评论

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