我希望您能告诉我最佳的异常处理方式,因为在我的
Try
语句中,有很多验证,如果出现了一些 Exception
,那么我的 Catch
语句可以告诉我发生了什么,但是我如何知道哪个字段出现了 Exception
?
示例代码
try
{
// If I get a Exception when converting to number,
// I will understand the error
// but how could I know where in my `Try` statement was the error ?
int valor = Convert.ToInt32(xmlnode[i].ChildNodes.Item(2).InnerText.Trim());
// A Lot of another validations here
}
Catch(Exception e)
{
this.LogInformation(e.Message);
}