Error Trapping

Results 1 to 2 of 2

Thread: Error Trapping

  1. #1
    Ima Hogg Guest

    Default Error Trapping

    Could someone explain error trapping and possibly provide some code? It sounds like a very good idea to have incorporated into a script.<BR><BR>TIA<BR><BR>Ima Hogg

  2. #2
    Join Date
    Dec 1969

    Default RE: Error Trapping

    In VBScript, you&#039ve only got one option for error handling. Put "On Error Resume Next" right after "Option Explicit" at the top of every script. Then check Err.Number at key points throughout your script to see if it&#039s non-zero, stopping execution if it is. At the end of your script, describe the error. Here&#039s an example.<BR><BR>Option Explicit<BR>On Error Resume Next<BR><BR>&#039 Your code goes here.<BR>Response.Write hello_world_str_this_is_an_error_since_I_didnt_dec lare_this_variable<BR><BR>&#039 Don&#039t carry on if an error has occurred.<BR>if Err.Number = 0 then<BR> Response.Write "Hello world." &#039 Won&#039t be seen.<BR>end if<BR><BR>if Err.Number &#060;&#062; 0 then<BR> Response.Write "Sorry, an error occurred: " & Err.Description & "(" & Err.Number & ", " & Err.Source & ")"<BR>end if<BR><BR>BTW - Only do this for production code. When debugging, it&#039s very hard to find errors unless the code stops at the exact spot of the error, and that only happens if you don&#039t say "On Error Resume Next". Fortunately, you can use code to decide whether to say "On Error Resume Next":<BR><BR>if Application("IsProduction") then<BR> On Error Resume Next<BR>end if<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts