现在的位置: 首页 > 综合 > 正文

可能你没有注意的Exception的属性

2012年10月12日 ⁄ 综合 ⁄ 共 555字 ⁄ 字号 评论关闭
每次总是
catch(Exception ee)
{
    MesageBox.Show(ee.Message);
}

昨天晚上看书,发现了fcl里面很多Exception 的继承类,可以提供更多的一场相关信息。今天找了OleDbException ,巴适!

      

catch(System.Data.OleDb.OleDbException ee)
      
{
       
for (int j=0; j < ee.Errors.Count; j++)
       
{
        MessageBox.Show(
"Index #" + j + " " +
         
"Message: " + ee.Errors[j].Message + " " +
         
"Native: " + ee.Errors[j].NativeError.ToString() + " " +
         
"Source: " + ee.Errors[j].Source + " " +
         
"SQL: " + ee.Errors[j].SQLState + " ");
       }

      }

再比如System.ArgumentException.ParamName属性。呵呵,这样的东西还有很多。

抱歉!评论已关闭.