Handling exceptions dynamically with message
Try
Catch ex As Exception
MessageBox("Error: " & ex.Message.ToString() & " :: " & _
ex.StackTrace())
End Try
Code to display Message Box
Private Sub MessageBox(ByVal msg As String)
Dim lbl As New Label()
' add the javascript to fire an alertbox to the label and
' add the string argument passed to the subroutine as the
' message payload for the alertbox
lbl.Text = "<script language='javascript'>" & Environment.NewLine & _
"window.alert('" + msg + "')</script>"
' add the label to the page to display the alertbox
Page.Controls.Add(lbl)
End Sub