<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        asp.net 的錯誤處理機制講解

        來源:懂視網 責編:小采 時間:2020-11-27 22:45:28
        文檔

        asp.net 的錯誤處理機制講解

        asp.net 的錯誤處理機制講解:程序健壯性最基本要求就是程序錯誤的處理與捕捉,在ASP.NET中,錯誤的處理有和其他編程語言一樣的機制,可以使用Try…Catch…Finally等方式,這一點和ASP相比具有較大的進步。而且,使用這些錯誤處理方法,可以大大提高程序的可讀性和程序調試速度,在這幾個
        推薦度:
        導讀asp.net 的錯誤處理機制講解:程序健壯性最基本要求就是程序錯誤的處理與捕捉,在ASP.NET中,錯誤的處理有和其他編程語言一樣的機制,可以使用Try…Catch…Finally等方式,這一點和ASP相比具有較大的進步。而且,使用這些錯誤處理方法,可以大大提高程序的可讀性和程序調試速度,在這幾個

        程序健壯性最基本要求就是程序錯誤的處理與捕捉,在ASP.NET中,錯誤的處理有和其他編程語言一樣的機制,可以使用Try…Catch…Finally等方式,這一點和ASP相比具有較大的進步。而且,使用這些錯誤處理方法,可以大大提高程序的可讀性和程序調試速度,在這幾個優勢結合的情況下,我們更加應該注意這一點。 
        關于錯誤的處理,我們可以參考這篇文章:

        Try...Catch...Finally in ASP.NET

        Introduction
        Error handling in Classic ASP was not the best. We were having only limited options available for error handling in Classic ASP such as, "On Error Resume Next". In ASP 3.0 we saw the new ASP object called Error Object. But we were not able to handle all exception/errors efficiently. Now in ASP.NET we have a new error handling mechanism which was already their in other languages such as C, C++ and JAVA. We can also call the try...catch mechanism as "Exception Handling" 

        What is Try...Catch....Finally
        This is a new error handling mechanism in VB.NET, so as in ASP.NET. Well we have three blocks of code, were each block has it own functionality. The Try...Catch...Finally block of code surrounds the code where an exception might occur. The simple Try statement comes before the block of code, the Catch block of code is where we specify what type of error to look for, and the Finally block of code is always executed and contains cleanup routines for exception situations. Since the catch block is specific to the type of error we want to catch, we will often use multiple Catch blocks in our Try...Catch...Finally structure. 

        A simple Database operation
        Dim mySqlConnection as New SqlConnection (ConnectionString) 
        Dim mySqlCommand as SqlCommand 
        Dim strSql as String 

        strSql = "insert into yourtable (f1, f2) values ('f1', 'f2')" 
        mySqlCommand = new SqlCommand(strSql, mySqlConnection) 

        Try 

        mySqlConnection.Open() 
        mySqlCommand.ExecuteReader(CommandBehavior.CloseConnection) 
        Message.text = "New Forward information added" 

        Catch SQLexc as sqlexception 

        Message.text = Message.text + sqlexc.tostring() 

        Catch exc as exception 

        if Instr(1, exc.tostring, "duplicate key") > 0 then 
        Message.text = Message.text + "Cannot insert duplicate values." 
        else 
        Message.text = Message.text + exc.tostring() 
        end if 

        Finally 

        mySqlConnection.Close() 
        End Try 


        What does the above example exactly do?
        Well, in the above example we were trying to insert some values to a database table. The possible chances while performing a database operation are invalid connection string, database server too busy resulting in connection time out, database server not currently running etc etc. We should anticipate all these errors while performing a database operation. So, we have a Try block, which contains the statements such as opening the connection and executing the operation. Basically, we have two major statements inside the try block which may result in an exception/error. 

        As I said, any exception can occur during a database operation. Catching all these exception is now very easy with the Catch block. All we need is to have a Catch block. We can have any number of Catch blocks. Each Catch block may have a different error/exception trapping mechanism. In the above example, we have two catch blocks, one which captures a general exception and the other one which traps the SqlException. 

        When all the statements inside the catch blocks are executed, the finally block comes into the picture. As I said earlier, finally block contains cleanup routines for exception situations. 

        Exit Try statement
        We can also have the Exit Try statement inside any of the try...catch block. The objective of this statement is to break out of the Try or Catch block. Once the Exit Try statement is executed, the control goes to the Finally block. So, Exit Try statement can be best used were we need to execute the cleanup routines. 

        How about nested Try statments?
        We can have nested Try and Catch blocks. Can you imagine, when we should use nested try statements. Well, errors can occur within the Catch portion of the Try structures, and cause further exception to occur. The ability to nest try structures is available so that we can use a second Try structure to cover exceptions. 

        Links
        http://www.vbweb.co.uk/show/1889/2/ http://www.oreillynet.com/pub/a/dotnet/2001/09/04/error_handling.html?page=2

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        asp.net 的錯誤處理機制講解

        asp.net 的錯誤處理機制講解:程序健壯性最基本要求就是程序錯誤的處理與捕捉,在ASP.NET中,錯誤的處理有和其他編程語言一樣的機制,可以使用Try…Catch…Finally等方式,這一點和ASP相比具有較大的進步。而且,使用這些錯誤處理方法,可以大大提高程序的可讀性和程序調試速度,在這幾個
        推薦度:
        標簽: 處理 錯誤 錯誤的
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲 自拍 另类小说综合图区| 91精品免费不卡在线观看| 最新中文字幕电影免费观看| 亚洲国产精品久久久天堂| 深夜福利在线视频免费| 免费a级毛片在线观看| 亚洲精品国产福利一二区| 久久亚洲AV无码精品色午夜麻豆 | 国产成人不卡亚洲精品91| 成人免费看黄20分钟| 亚洲国产美女精品久久久| 三级黄色片免费看| 久久久久久久尹人综合网亚洲| 99精品视频在线观看免费| 在线观看免费精品国产| 国产成人亚洲精品蜜芽影院| 亚洲国产一区视频| 中文字幕高清免费不卡视频| 亚洲国产精品久久66| 国产精品成人啪精品视频免费| 国产91精品一区二区麻豆亚洲| 亚洲一本到无码av中文字幕| 久久国产精品成人片免费| 亚洲免费黄色网址| 日韩免费福利视频| 巨胸喷奶水视频www免费视频| 亚洲av一综合av一区| 成人国产精品免费视频| 亚洲AV无码第一区二区三区| 免费可以在线看A∨网站| 亚洲福利视频一区二区三区| 女人18一级毛片免费观看| 亚洲人成日本在线观看| 免费看国产精品麻豆| 成人无码WWW免费视频| 亚洲日本乱码卡2卡3卡新区| 毛片A级毛片免费播放| 人妖系列免费网站观看| 亚洲天堂中文字幕| 全部免费毛片在线| 51在线视频免费观看视频|