Types of Programming Errors

Started by OmMuruga, Feb 07, 2009, 01:26 PM

Previous topic - Next topic

OmMuruga

Types of Program Errors

    There are three basic types of program errors. Obviously, your objective is to write programs that are totally free of program errors. Program errors are also referred to as program bugs . (The term " bug " was created because one of the earliest program errors ever detected involved a moth flying into the computer and short - circuiting the electronics. The process of removing program errors is called debugging .) While that goal is laudable, every programmer, no matter how seasoned, writes programs that contain errors. A skilled programmer, however, can detect, isolate, and correct program errors more quickly than a less skilled programmer. Also, experienced programmers do make fewer programming errors simply because of their experience. The lesson here is that you should expect to make a lot of program errors in the beginning . . . every beginner does.

        In the beginning you will start off with the " flat - forehead " type of programming error. Those are the kind of errors that, when you do find them, you slam the heel of your hand into your forehead while mumbling, " How could I make such a silly mistake? " Relax. We ' ve all made those mistakes ... and still do! The key is not to get discouraged. View each program error as a challenge and learn from the experience. Alas, as your programming skills advance, so will the type of errors you make. While there will be fewer errors as you gain experience, those errors you do make tend to become more sophisticated and harder to isolate and fix.
Let ' s take a quick overview of the three types of program errors. I will have a lot more to say about errors For now, however, let ' s just categorize the types of program errors.

   Syntax Errors

            The first type of error is a syntax error. You already know that syntax errors are caused when you don ' t obey the syntax rules of C#. A common syntax rule you might make in the beginning is forgetting to terminate each program statement with a semicolon.
Intellisense does an excellent job of catching syntax errors. While you may hate the squiggly line
that Intellisense displays, it ' s a lot easier for Intellisense to detect and isolate syntax errors than it is for you to do it yourself.


Logic Errors

       Logic errors are those errors that remain after all the semantic and syntax errors have been removed. Usually, logic errors manifest themselves when the result the program produces doesn ' t match the result your test data suggest it should produce. Most of the time, logic errors are found in the Process  . Logic errors occur when you implement the algorithm for solving the problem incorrectly.
The key to fixing logic errors is to be able to reproduce the error consistently. A repeatable logic error is much easier to track down and fix than an error that appears to be occurring randomly. you will learn the details of using some of the tools Visual Studio provides to help you detect and isolate program bugs.)

Semantic Errors

        A semantic error occurs when you obey the syntax rules of the language but are using the statement out of context. For example, a sentence in English is expected to have a noun and a verb. Consider the sentence " The dog  meowed. " This sentence does obey the rules of having a noun and a verb, but the context of the sentence is out of whack. Dogs don ' t meow, therefore the context of the statement is incorrect. The error message I showed you earlier:
The name 'i' does not exist in the current context refers to a type of semantic error. There may well be a variable named i defined somewhere in the program, but it is not currently in scope. That is, you are trying to use i when it is out of scope.Intellisense does a good job of detecting semantic errors.
:acumen :acumen

Ominto

This is a very good post which I really enjoy reading. It is not every day that I have the possibility to see something like this.