On Error...Need a professional's comment

Results 1 to 3 of 3

Thread: On Error...Need a professional's comment

  1. #1
    Join Date
    Dec 1969

    Default On Error...Need a professional's comment

    Hi, <BR><BR>I have been reading my wrox book (professional ASP 3.0 p295). I basically would like to trap any errors in my script. The script uses select statements to run subroutines etc...writing html to the page. At the very top of the page I am putting an On Error Resume Next...then all the code, subroutines, functions....run and complete. At the end of the script I check... <BR><BR>If Err.Number &#060;&#062; 0 Then <BR> Response.WRite "Error...yadadadada" <BR> On Error Goto 0 <BR>End If <BR><BR>I guess my question is...is this on ok way to do this? Is On Error Resume Next meant to be able to have alot running "Inside" of it (subroutines, functions, and one nested subroutine)...then catching it at the very end? This would be alot easire than putting on error resume next and on error goto 0 in each subroutine for all database adds, updates, or delete etc... <BR><BR>Are there any problems I might encounter that I am not seeing? <BR><BR>Do the professionals use a method like this maybe? <BR><BR>Thanks for any thoughts. <BR><BR>Smo<BR><BR>Sorry for the repost from yesterday. I have tried 3 message baords on the net...can&#039;t seem to get an answer.

  2. #2
    Join Date
    Dec 1969

    Default RE: On Error...Need a professional's comment

    At our firm we use something similar....error trapping in ASP is not the most graceful thing and this is what i see most people doing...I would try to evaluate for an error more often than once at the end of the page...do it where you think an error might occurr then respond to it.

  3. #3
    Bonedaddy Guest

    Default RE: On Error...Need a professional's comment

    I&#039;m no professional... but here&#039;s my 2 cents.<BR><BR>It is in my humble opinion that blanketing a page with a single On Error Resume Next at the top is not the best way to handle errors. Often it is important to know that an error has occurred.. especially critical errors. I don&#039;t know how many times I have been bitten by making the assumption that a page is executing perfectly only to find out that an error is occurring every time -- but that error is hidden from me because of the "On Error..." line at the top.<BR><BR>If not used wisely, the "On Error Resume Next" line might as well read "On Error Continue As Though It Didn&#039;t Happen".<BR><BR>FYI, what I do for ASP error handling is this: wrap the statements where an error is most likely to occur in "On Error..." statement, as follows:<BR><BR>&#060;%<BR>On Error Resume Next &#039; turn default error handling OFF<BR>&#060;do something where an error is likely to occur&#062;<BR>On Error GoTo 0 &#039; turn default error handling back ON<BR>%&#062;<BR><BR>For example.. when connecting to a database I do the following:<BR><BR>&#060;%<BR>On Error Resume Next<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>objConn .Open GetConnectionString()<BR>If objConn.State &#060;&#062; adStateOpen Then<BR> Response.Redirect "connection_failed.asp"<BR>End If<BR>On Error GoTo 0<BR>%&#062;<BR><BR>Referring to the code above: I turn on custom error handling then attempt to connect to the database; if the connection fails, the next line is still executed, which checks to see if the connection did indeed fail; if it failed, I redirect to a page, otherwise, everything is fine and I return the error handling back to the default handling. This is a much more user-friendly method handling of an error.<BR><BR>:)<BR><BR>Kevin Turner<BR>(Mississauga, Canada)

Posting Permissions

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