Thursday, August 16, 2012

Error Handling


. Error Handling



  • Use “On Error Resume Next” statement at the beginning of each procedure and function.
  • Use “On Error GoTo 0” at the end of each procedure or function
  • Show errors to the user in some standard message box



Compare the following code fragments:

If Bug_Fields(“BG_SEVERITY”).Value = “4-Urgent” Then
        Bug_Fields(“BG_PRIORITY”).Value = “4-Urgent”
End If
On Error Resume Next
...
If Bug_Fields(“BG_SEVERITY”).Value = “4-Urgent” Then
        Bug_Fields(“BG_PRIORITY”).Value = “4-Urgent”
End If
...
PrintError “SomeSub”
On Error GoTo 0

The both code fragments will work the same way when no problems arise during the code execution. But what happens if, for example, the user has no permissions to modify BG_PRIORITY field? The left fragment will not update the field and will cause the browser crash. The second will not update the field, but it will show the correct error to the user and the browser will not crash.

No comments:

Post a Comment