Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling in global.asax

Status
Not open for further replies.

MrPink1138

Programmer
Jul 10, 2003
34
US
I'm trying to write a script that will email me everytime an error occurs in my web app.
I have a global.asax file with the following code...
Code:
Protected Sub Application_Error(sender As Object, e As EventArgs)
	Dim ex As Exception = Server.GetLastError().GetBaseException()
	Dim exEmail As string

	exEmail = "MESSAGE: " & ex.Message.ToString() & vbCrLf & _
     "SOURCE: " & ex.Source.ToString() & vbCrLf & _
     "FORM: " & Request.Form.ToString() & vbCrLf & _
     "PATH: " & Request.Path.ToString() & vbCrLf & _
     "TARGETSITE: " & ex.TargetSite.ToString() & vbCrLf & _
     "STACKTRACE: " & ex.StackTrace.ToString()
   EmailException(exEmail)
End Sub 'Application_Error


Private Sub EmailException(ex As String)
	Dim msgBody As String

	msgBody = ex
	SmtpMail.Send ("my@eamil.com", "my@email.com", "DB: An exception occurred.", msgBody )
End Sub 'EmailException

This code works fine and sends me an email that looks like...
MESSAGE: External component has thrown an exception.
SOURCE: System.Web
FORM:
PATH: /mysite/test.aspx
TARGETSITE: Void ThrowIfCompilerErrors(System.CodeDom.Compiler.CompilerResults, System.CodeDom.Compiler.CodeDomProvider, System.CodeDom.CodeCompileUnit, System.String, System.String)
STACKTRACE: at System.Web.Compilation.BaseCompiler.ThrowIfCompilerErrors(CompilerResults results, CodeDomProvider codeProvider, CodeCompileUnit sourceData, String sourceFile, String sourceString)
at System.Web.Compilation.BaseCompiler.GetCompiledType()
at System.Web.UI.PageParser.CompileIntoType()
at System.Web.UI.TemplateParser.GetParserCacheItemThroughCompilation()


That information isn't really helpful. What I really want is what shows up on the screen when an error occurs...

Compiler Error Message: BC30451: Name 'test' is not declared.

Source Error:
Line 3:
Line 4: Sub Page_Load
Line 5: test.text = "test"
Line 6: End Sub
Line 7: </script>


Source File: D:\Inetput\mysite\test.aspx Line: 5


Does anyone know a way to get that information programmatically? Any help here would be greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top