在我的應用程序中,我不明白如何處理system.format異常。請參見下面的代碼句柄system.format異常C#
public Harvest_Project(XmlNode node)
{
this._node = node;
this._name = node.SelectSingleNode("name").InnerText;
this._created_at = storeTime(node.SelectSingleNode("created-at").InnerText);
this._updated_at = storeTime(node.SelectSingleNode("updated-at").InnerText);
this._over_budget_notified_at = storeTime(node.SelectSingleNode("over-budget-notified-at").InnerText);
this._latest_record_at = storeTime(node.SelectSingleNode("hint-latest-record-at").InnerText);
this._earliest_record_at = storeTime(node.SelectSingleNode("hint-earliest-record-at").InnerText);
this._billable = bool.Parse(node.SelectSingleNode("billable").InnerText);
try
{
this._id = Convert.ToInt32(node.SelectSingleNode("id").InnerText);
this._client_id = Convert.ToInt32(node.SelectSingleNode("client-id").InnerText);
this._budget = float.Parse(node.SelectSingleNode("budget").InnerText);
this._fees = Convert.ToInt32(getXmlNode("fees", node));
}
catch (FormatException e)
{
Console.WriteLine();
}
catch (OverflowException e)
{
Console.WriteLine("The number cannot fit in an Int32.");
}
this._code = node.SelectSingleNode("code").InnerText;
this._notes = node.SelectSingleNode("notes").InnerText;
}
在這裏,嘗試和catch塊,所有的節點需要int類型,但是,作爲_fees以「0」值。它顯示我格式異常。我只想讓我的節點不顯示空字符串。我想處理這個異常。這意味着,它不應該拋出異常在「this._fees = Convert.ToInt32(getXmlNode(」fees「,node));」因爲它返回我想要的int值。
我怎麼能做到這一點?
[文檔在這裏(http://msdn.microsoft.com/en-us/library/f02979c7.aspx) – tnw
我是WPF的新手,我應該在哪寫這篇文章? – user2622971