隨筆 - 78  文章 - 25  trackbacks - 0
          <2013年12月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿

          隨筆分類(75)

          隨筆檔案(78)

          相冊

          實(shí)用Links

          我的Links

          搜索

          •  

          積分與排名

          • 積分 - 114431
          • 排名 - 515

          最新評論

          閱讀排行榜

          評論排行榜

          ■Exception類的主要成員:
          Exception:構(gòu)造函數(shù),構(gòu)造一個異常類,制定其異常消息,發(fā)生位置
          Message:只讀屬性,獲取當(dāng)前異常提供的消息,該消息在構(gòu)造異常時指定
          Source:讀寫屬性,獲取和設(shè)置引起該異常的應(yīng)用程序或?qū)ο蟮拿Q
          TargetSite:只讀屬性,獲取引發(fā)該異常的方法
          ToString:公開方法,創(chuàng)建該異常的字符串表示形式,包括異常發(fā)生的位置,名稱等信息

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;

          namespace ThrowException
          {
              
          class Program
              {
                  
          static void Main(string[] args)
                  {
                      
          try {
                          ThrowAnException();
                      }
          catch(Exception e){
                          ShowException(e);
                      }
                      System.Console.ReadLine();
                  }
                  
          static void ThrowAnException() {
                      
          throw new Exception("This is an Exception!");
                  }
                  
          static void ShowException(Exception e) {
                      System.Console.WriteLine(
          "An Exception information:");
                      System.Console.WriteLine(
          "Type:{0}  ",e.GetType().Name);
                      System.Console.WriteLine(
          "Message:{0}",e.Message);
                      System.Console.WriteLine(
          "Source:{0}",e.Source);
                      System.Console.WriteLine(
          "TargetSite:{0}",e.TargetSite);
                      System.Console.WriteLine(
          "ToString:{0}",e.ToString());
                      System.Console.WriteLine(
          "StackTrace:{0}",e.StackTrace);
                  }
              }
          }


          結(jié)果:
          An Exception information:
          ......Type:Exception
          ......Message:This is an Exception!
          ......Source:ThrowException
          ......TargetSite:Void ThrowAnException()
          ......ToString:System.Exception: This is an Exception!
             在 ThrowException.Program.ThrowAnException() 位置 g:"TrueStudy"cSharp"project
          s"ConsoleAppl"ThrowException"Program.cs:行號 20
             在 ThrowException.Program.Main(String[] args) 位置 g:"TrueStudy"cSharp"projec
          ts"ConsoleAppl"ThrowException"Program.cs:行號 13
          ......StackTrace:   在 ThrowException.Program.ThrowAnException() 位置 g:"TrueStu
          dy"cSharp"projects"ConsoleAppl"ThrowException"Program.cs:行號 20
             在 ThrowException.Program.Main(String[] args) 位置 g:"TrueStudy"cSharp"projec
          ts"ConsoleAppl"ThrowException"Program.cs:行號 13



          posted on 2009-10-26 19:06 期待明天 閱讀(1397) 評論(1)  編輯  收藏 所屬分類: CSharp

          FeedBack:
          # re: 異常類Exception 2013-12-15 13:27 常磊
          57預(yù)估  回復(fù)  更多評論
            
          主站蜘蛛池模板: 大埔区| 汽车| 邻水| 新民市| 雷州市| 墨江| 安远县| 孝感市| 遵义市| 沈丘县| 蕉岭县| 芦溪县| 冀州市| 噶尔县| 竹溪县| 长岭县| 奈曼旗| 唐河县| 隆化县| 喜德县| 铜陵市| 宁明县| 含山县| 革吉县| 罗源县| 深圳市| 盱眙县| 治县。| 榕江县| 左贡县| 府谷县| 武安市| 新巴尔虎左旗| 南木林县| 阿瓦提县| 弥勒县| 昌平区| 荥经县| 绵阳市| 嘉善县| 安国市|