<%@ Page Language="VB" %>
<html>
<head>
<title>Examining the Last Error</title>
<script runat="server">
Sub CauseError(sender As Object, e As EventArgs)
Dim x, y, z As Integer
y = 1
z = 0
x = y / z
End Sub
Sub Page_Error(Source As Object, E As EventArgs)
Dim LastError As Exception
Dim ErrMessage As String
LastError = Server.GetLastError()
If Not LastError Is Nothing Then
ErrMessage = LastError.Message
Else
ErrMessage = "No Errors"
End If
Response.Write("Last Error = " & ErrMessage & "<br/><br/>")
Server.ClearError()
End Sub
</script>
</head>
<body>
<form runat="server">
<h4><font face="verdana">Cause an Error to Occur...</font></h4>
<asp:button text="CauseError" OnClick="CauseError" runat="server"/>
</form>
</body>
</html>