SQLConfigurationSQLConfiguration





Data Access  «Prev  Next»
Lesson 9 Defensive programming: handling errors
Objective Include general error-handling code in an asp page.

Defensive Programming - Handling Errors

There is a chance that your Web application will have an occasional error. Regardless of the quality of the application, there are other factors that can cause things to go awry, such as database web applications. You should plan for this possibility and include some level of error handling in the application.
Handling errors in database-centered Web applications is really no different than handling errors in other types of applications. You just try to anticipate what could go wrong and add the necessary programming logic to catch and handle the error.

Types of errors

Typical database-related errors you should plan for include:
  1. Failures to connect to a database
  2. Failures to open a database
  3. Failed query

Sources of error problems

Errors can result from any of the following:
  1. Network problem
  2. Hardware problem
  3. Security or administrative problem
  4. Number of users already accessing the system
  5. Corrupted database



Avoiding errors

The scripting language you are using should have error-handling capability. For example, Visual Basic Script has the On Error Resume Next statement , and JavaScript has the try-catch statement. These can be used to respond in some manner to an error condition. The ToolTip below shows how the VBScript On Error Resume Next statement is used to trap an error condition.
The On Error Resume Next statement tells VBScript to resume program execution on the line immediately following the one
Handling Errors Using vbScript

The On Error Resume Next statement does not do anything about the error. Instead, it keeps the program from crashing.
Remember, handling the error is still the programmer's responsibility. The next lesson wraps up the module and concludes with a quiz.