when vb throws error

I am trying to set up my code that if my vb page throws an error it should just go next and not stop the page, But i want to see the 500 error message

So i put something like this.
if Request.ServerVariables("REMOTE_ADDR") = myipaddress then 
	On Error goto 0 
	else
	On Error Resume Next
end if 

Open in new window

But really, I want if the page hits a 500 error, it should send me an email, but for the client it should continue loading the page.

How can I code that?
rivkamakAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
microsoft has a KB explaining how to set up a custom 500 error page.

instead of writing out the errors to the screen, just stick the info you want into a variable and email it to yourself.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
There is an old article from 4 guys that explains this nicely.  

What you want to do is start each page with <% On Error Resume Next %>.
Next, create an include file that you will add to every page. That code sample for the include file can look like below.  Note that the email portion was outdated and I updated using cdo instead of cdonts.

<%
Dim strErrorMessage
Dim bolErrors

'Initialize variables
strErrorMessage = ""	'The error messages for tech. support
bolErrors = False	'Have we found any errors yet?

'Now our two subs
sub TrapError(strError)
  bolErrors = True	'Egad, we've found an error!

  strErrorMessage = strErrorMessage & strError & ", "
end sub

'If there are any errors, this function will email tech. support
sub ProcessErrors()
  if bolErrors then
    'Send the email
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "AN ADO ERROR OCCURRED"
objMessage.From = "techsupport@mysite.com" 
objMessage.To = "techsupport@mysite.com"
objMessage.TextBody =  "At " & Now & " the following errors occurred on " & _
		  "the page " & Request.ServerVariables("SCRIPT_NAME") & _
		  ": " & _
                  chr(10) & chr(10) & strErrorMessage
objMessage.Send


    'Now, we've got to print out something for the user
    Response.Write "There has been a database error.  Technical Support " & _
                   "has already been notified.  You will be informed when " & _
                   "this issue is resolved.  Thank you for your patience!"
  end if
end sub  

Open in new window


You will want to adjust this to meet your needs perhaps instead of a response.write set a area in your site to show the message if there is an error as a modal or message.
if strErrorMessage<>"" then
    response.write "<div class='error'>"&strErrorMessage&"</div>
end if

Open in new window

For reference http://www.4guysfromrolla.com/webtech/060399-1.2.shtml and email http://www.paulsadowski.com/wsh/cdo.htm

I also would suggest writing the error to  your database and keeping a log. Emails can get  lost.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Edit to my previous post.  The last line of asp code on each page should be
<% ProcessErrors %>

Open in new window

0
rivkamakAuthor Commented:
If you can still help me,
how come this runs the page and resume next works. the error msgbox populates, but the page continues running.
Dim x, y ,z
On Error Resume Next

x = 10
y = 0
z = x / y
If Err.Number <> 0 Then
   MsgBox "Error number " & Err.Number & ", " & _
          Err.Description & ", has occurred"
   Err.Clear
Else
   MsgBox z
End If

z = x * y
If Err.Number <> 0 Then
   MsgBox "Error No:" & Err.Number & " - " & _
          Err.Description & " has occurred"
   Err.Clear
Else
   Alert z
End If

Open in new window



but when I replace with a different type of error, I get the 500 page.
<%
Dim x, y ,z
On Error Resume Next

pagename = "test"
if pagename = "test" then
response.write("test it ")


If Err.Number <> 0 Then
   MsgBoxText = "Error number " & Err.Number & ", " & _
          Err.Description & ", has occurred"
   Err.Clear
Else
   response.write "<br>pg: " & pagename
End If

pagename = "<br>test2"
   response.write "<br>pg2: " & pagename
response.write("<br>Msg: " & MsgBoxText)
%>

Open in new window

0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
When you are testing like this, turn on sending errors to the browser so you can see the actual error.

Also when you are coding, it will help you identify problems if you indent.  The code in both box's are below are the same with the same type of error that you are having.   The bottom code box you can spot the problem pretty quickly.  
dim x,y,z
x=1
y=2
z=3
if x <> 2 then
 response.write y
 response.write z-x
 if z > 2 then
 if z= 3 then
 response.write "z is 3"
 end if
end if

Open in new window

dim x,y,z
x=1
y=2
z=3
if x <> 2 then
     response.write y
     response.write z-x
     
     if z > 2 then
          if z= 3 then
               response.write "z is 3"

    end if

end if

Open in new window


Your issue is you have an if pagename= "test" then on line 6 but no closing end if.
0
rivkamakAuthor Commented:
Let me rephrase.
both pages has ' on error resume next'
the math problem that 0 can not be divided , the page resumes properly.
I also tested, when it's a script that should be on 1 line but takes up 2, with an extra line break, also the page resumes.

But if the error is of a different kind, like I left out an end if, the page doesn't resume next, it throws a 500 page.
Any idea what the difference is in the error type?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.