我爱Aspx >> Asp.Net >> Try...Catch...Finally 和Throw 叙述Sub Button1_Click(Sender As Object,e As Eventargs)
Try
Response.Write("自行丢出一个Exception 例外<Br>")
Throw New Exception
Catch ex As Exception
Response.Write(ex.ToString())
End Try
End Sub
</Script>
</Html>

Try....Catch 的结构化使得我们的例外处理变的相当有效率,我们可以在程序代码中使用Try....Catch 结构来处里我们的例外,不用担心程序的执行流程被改变。使用Try....Catch 要注意不破坏原有的程序代码结构,例如下列程序代码片段是错误的示范:
Try
For shtI=0 To 9
Response.Write(shtI)
Catch ex As Exception
...
Next
巢状的Try...Catch
我们可以在Catch 区块或Finally 区块中再使用Try....Catch 叙述,如下列范例所示:
<Html>
<Form Runat="Server">
<ASP:Button Id="Button1" Text="产生例外" OnClick="Button1_Click"
Runat="Server"/>
</Form>
<Script Language="VB" Runat="Server">
Sub Button1_Click(Sender As Object,e As Eventargs)
Try
Response.Write("自行丢出一个Exception 例外<P>")
Throw New Exception
Catch err As Exception
Try
Response.Write(err.ToString() & "<P>")
Response.Write("再产生一个例外<P>")
Throw New IndexOutOfRangeException()
Catch err1 As IndexOutOfRangeException
Response.Write(err1.ToString())
End Try
End Try
End Sub
</Script>
</Html>
常见的例外对象[04-29]
使用Debug 工具列[04-29]
可视化的除错工具[04-29]
Session 物件[04-29]
锁定Application 物件[04-29]
设定Session 对象变量的有效期限[04-29]
Cookie 物件[04-29]
程序的追踪及检视[04-29]
自订CookieCollection 及Cookie ..[04-29]
设定Cookie 变量的生命周期[04-29]