亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > .NET > 正文

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

2024-07-10 13:14:41
字體:
來源:轉載
供稿:網友
程序健壯性最基本要求就是程序錯誤的處理與捕捉,在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 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
色老头一区二区三区在线观看| 国产精国产精品| 热久久99这里有精品| 日韩电影免费在线观看| 久久人人爽人人爽人人片亚洲| 尤物99国产成人精品视频| 亲子乱一区二区三区电影| 国产日韩在线免费| 亚洲国产毛片完整版| 91免费欧美精品| 国产美女被下药99| 91久久综合亚洲鲁鲁五月天| 2019国产精品自在线拍国产不卡| 91色中文字幕| 色偷偷av亚洲男人的天堂| 久久精品国产亚洲一区二区| 亚洲最大成人在线| 亚洲九九九在线观看| 日韩欧美在线视频免费观看| 亚洲va电影大全| 国产香蕉一区二区三区在线视频| 久久精品最新地址| 日韩激情av在线免费观看| 中文日韩在线视频| 国产自摸综合网| 国产精品亚洲视频在线观看| 午夜精品一区二区三区在线视| 亚洲区中文字幕| 奇米影视亚洲狠狠色| 亚洲xxxx3d| 中文字幕精品在线视频| 欧美日韩免费在线| 欧美成人精品在线播放| 亚洲人成电影在线观看天堂色| 久久精品成人一区二区三区| 亚洲欧美日韩精品久久奇米色影视| 自拍视频国产精品| 中文字幕精品一区久久久久| 国产精品啪视频| 亚洲国产精品美女| 久久99精品久久久久久噜噜| 久久夜色撩人精品| 久久成人一区二区| 久久影院中文字幕| 日本韩国欧美精品大片卡二| 北条麻妃一区二区在线观看| 亚洲少妇激情视频| 欧美人在线观看| 国产精品美女呻吟| 国产91久久婷婷一区二区| 精品视频在线播放| 中文在线不卡视频| 亚洲人成亚洲人成在线观看| www.久久色.com| 在线看日韩欧美| 亚洲人高潮女人毛茸茸| 亚洲精品久久久久| 欧美中文字幕视频在线观看| 九九精品视频在线观看| 午夜精品久久久久久久久久久久久| 国产美女久久精品香蕉69| 精品动漫一区二区三区| 欧美激情性做爰免费视频| 日韩电影在线观看中文字幕| 日韩中文在线观看| 国产一区二区成人| 精品自在线视频| 日本a级片电影一区二区| 欧美大全免费观看电视剧大泉洋| 2018中文字幕一区二区三区| 日韩av不卡在线| 91视频免费在线| 亚洲国产精品va在线观看黑人| 91青草视频久久| 日韩在线一区二区三区免费视频| 亚洲无亚洲人成网站77777| 亚洲欧洲日韩国产| 亚洲欧美中文字幕| 俺也去精品视频在线观看| 1769国产精品| 在线观看不卡av| 欧美日韩视频免费播放| 国产91九色视频| 亚洲亚裔videos黑人hd| 国内精品久久久久久中文字幕| 欲色天天网综合久久| 欧美日本啪啪无遮挡网站| 日韩va亚洲va欧洲va国产| 九九九热精品免费视频观看网站| 91麻豆国产语对白在线观看| 亚洲天堂男人天堂女人天堂| 久久久久久久一区二区| 97在线视频精品| 欧美成人亚洲成人| 精品久久久国产| 亚洲精品日韩在线| 欧美精品在线视频观看| 九色91av视频| 亚洲第一精品夜夜躁人人躁| 欧美老女人bb| 国产精品video| 91在线视频精品| 色多多国产成人永久免费网站| 欧美日韩综合视频| 日韩中文字幕精品| 亚洲人成五月天| 97香蕉久久超级碰碰高清版| 精品国产依人香蕉在线精品| 97视频在线观看视频免费视频| 国产成人avxxxxx在线看| 亚洲欧美国产日韩天堂区| 亚洲乱码一区av黑人高潮| 久久久久久综合网天天| 免费99精品国产自在在线| 久久免费视频这里只有精品| 国模私拍一区二区三区| 亚洲无限乱码一二三四麻| 日本欧美中文字幕| 久久中文字幕国产| 国产精自产拍久久久久久| 久久精品男人天堂| 亚洲女人天堂色在线7777| 亚洲欧美综合区自拍另类| 日韩精品在线免费观看视频| 欧美中文在线字幕| 久久久精品免费视频| 日韩精品免费在线视频观看| 亚洲一区二区三区在线视频| 久久精品视频在线| 欧美理论片在线观看| 久久久久久国产精品| 亚洲精品一区中文| 国产精品一区二区3区| 国产亚洲精品美女久久久久| 久久久久久一区二区三区| 国产美女精彩久久| 日韩欧亚中文在线| 亚洲三级黄色在线观看| 亚洲黄色成人网| 久久久久久午夜| 国产精品一区二区3区| 欧洲中文字幕国产精品| 亚洲一区av在线播放| 中文字幕精品—区二区| 国产精品丝袜一区二区三区| 永久555www成人免费| 国产一区欧美二区三区| 久久视频在线观看免费| 欧美老妇交乱视频| 亚洲国产91色在线| 成人精品视频在线| 91精品视频在线播放| 日韩视频在线免费观看| 91高清视频免费观看| 欧美日韩亚洲成人| 国产精品美女在线观看| 国产精品成人国产乱一区| 欧美国产日本高清在线| 中文字幕亚洲图片| 国产综合色香蕉精品| 在线视频欧美日韩精品| 国产视频精品va久久久久久| 亚洲成年网站在线观看| 亚洲精品成人免费|