天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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

程序健壯性最基本要求就是程序錯誤的處理與捕捉,在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

AspNet技術asp.net 的錯誤處理機制講解,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 在教室伦流澡到高潮HNP视频 | 6080YYY午夜理论片在线观看 | 亚洲精品AV一二三区无码 | 99久久精品国产免费 | 荡公乱妇HD中文字幕 | 全彩无翼污之邪恶女教师 | 人妻体内射精一区二区 | 回复术士勇者免费观看全集 | 欧美亚洲日韩国产在线在线 | 日本久久免费大片 | 国产亚洲美女在线视频视频 | 国产又色又爽又刺激在线播放 | 被老总按在办公桌吸奶头 | 久久99国产精品蜜臀AV | 国产AV无码一二三区视频 | 99九九精品国产高清自在线 | 国产国拍精品AV在线观看 | 久久99re6热在线播放 | 国产精品爽爽久久久久久蜜桃网站 | 久久偷拍国2017的 | 入室强伦女教师被学生 | 野花日本大全免费高清完整版 | 两个女人互添下身高潮自视频 | 成人毛片免费观看视频大全 | 秋霞伦理高清视频在线 | 亚洲人成7777 | 日韩一区二区在线免费观看 | 欧美性黑吊xxx | 色姣姣狠狠撩综合网 | 羞羞漫画免费漫画页面在线看漫画秋蝉 | 色迷迷电影 | 蜜臀亚洲AV永久无码精品老司机 | 国产1广场舞丰满老女偷 | 亚洲精品国产品国语在线试看 | 动漫美女被爆挤奶歪歪漫画 | 久久亚洲精品成人综合 | 天美传媒 免费观看 | 亚洲精品视频在线播放 | 国产高清视频在线观看97 | 亚洲AV中文字幕无码久久 | 国产亚洲欧美ai在线看片 |