Share via


Debugging and Error Handling

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

All code contains errors of one kind or another, and how you deal with errors might be the most important part of a well-designed application. There are two categories of errors: those you can prevent, which are called development errors, and those you cannot prevent but can trap, which are called run-time errors.

Development errors are either syntax errors or logic errors. Syntax errors occur from typographical errors, missing punctuation, or improper use of a language element — for example, forgetting to properly terminate an If…Then…Else statement. Logic errors are more commonly referred to as "bugs." These errors occur when code executes without causing an error but does not produce the results intended. You eliminate development errors by "debugging" your code. Many tools exist that can help you debug script and Microsoft® Visual Basic® for Applications (VBA) code.

Run-time errors are errors that occur while the application is running. These are errors where otherwise correct code fails because of invalid data or system conditions that prevent the code from executing (for example, lack of available memory or disk space). You handle run-time errors by writing error handlers and by writing procedures that can validate program or environmental conditions in appropriate circumstances.

Successfully debugging code is more of an art than a science. The best results come from writing understandable, maintainable code and using the available debugging tools. When it comes to successful debugging, there is no substitute for patience, diligence, and a willingness to test relentlessly, using all the tools at your disposal.

Writing good error handlers is a matter of anticipating problems or conditions that are beyond your immediate control and that will prevent your code from executing correctly at run time. Writing a good error handler should be an integral part of the planning and design of a good procedure. It requires a thorough understanding of how the procedure works and how the procedure fits into the overall application. And, of course, writing good procedures is an essential part of building solid Microsoft® Office XP applications.

In This Section

  • Writing Error-Free Code
    When you write Microsoft® Visual Basic® for Applications (VBA) code, or script in an HTML page, it is not a question of "if" the code will contain errors but "when" those errors will be introduced and how many there will be.
  • Debugging Code
    Microsoft® Visual Basic® for Applications (VBA) provides several debugging tools that help analyze how code operates and help locate errors in your code.
  • Handling Errors
    When an error occurs in a procedure that does not have error handling enabled, Microsoft® Visual Basic® for Applications (VBA) responds by displaying an error message and terminating the application.
  • Developing Office Developer Applications
    Microsoft® Office XP Developer provides the productivity tools professional developers must have to build applications faster, integration tools to make their applications work seamlessly with data and the Web, and management tools to simplify deploying and managing the applications they build with Office.
  • Designing Applications
    Understand how planning a good effective design can mean delivering the application that customers require.
  • Developing Applications with Microsoft Office Developer
    Projects are the building blocks of a Microsoft® Office Developer application. If a project is a building block for an application, then an application is the foundation.
  • Adding Help to Your Custom Application
    Reduce the amount of time required to train and support users of your applications by adding online Help to your Microsoft® Office XP application.
  • Deploying Your Application
    Understanding how you choose to deploy the application depends largely on what type of application you have created.