Types of Visual Basic .NET Errors

Types of Visual Basic .NET Errors

In Visual Basic, errors are syntax errors, run-time errors, or logic errors. Syntax errors are the most common type of error, but they are also the easiest to fix. They appear while you write your code. As you know, Visual Basic .NET checks your code as you type and alerts you if you make a mistake such as misspelling a word or using a language element improperly. Because the compiler barks at you by underlining an error, you can fix it easily in the coding environment as soon as it occurs. As I touched on earlier, in Chapter 4, "Visual Basic .NET Data Types and Features," the Option Explicit statement is the best means of avoiding syntax errors. This statement forces a programmer to declare, in advance, all the variables that will be used in the application. When any of the predeclared variables are used in the code, any typographic errors made entering a variable name are caught immediately and can be fixed.

Run-time errors are those that appear only after you compile and run your code. They involve code that appears to be correct because it contains no syntax errors, but these errors cause a program to crash, as in the examples described earlier. For example, the Throwback program works until the user enters a string instead of a number. Run-time errors can be corrected by rewriting the offending code and then recompiling and rerunning your program.

Logic errors are those that appear after the application is in use. These errors usually manifest themselves in the form of unwanted or unexpected results in response to user actions. For example, you might have used the wrong index for your array, and the Throwback calculator displays an X when it should display an M. Logic errors are generally the hardest type of error to fix because their origin is not always clear. And sometimes logic errors are not obvious; the program displays incorrect information that looks as though it might be correct. This sort of situation is one in which a thorough understanding of how a program is expected to be used is important to the programmer.



Coding Techniques for Microsoft Visual Basic. NET
Coding Techniques for Microsoft Visual Basic .NET
ISBN: 0735612544
EAN: 2147483647
Year: 2002
Pages: 123
Authors: John Connell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net