Thursday, December 16, 2010

Program 12 - Program Test Data, Debugging and Termination: Program Errors


 

For this project, I have decided to compare the three programming languages, Java, C++, C#.

Design errors are errors that usually occur due to bad logic within the program, or due to making a program too fragile. Bad Logic usually appears when running a program, as it will either complete the task with an incorrect output, or the program will crash. Fragility tends to be due to the programmer not taking the time to protect the program from user made errors, such as entering alphabetic characters where numeric characters should be entered. Programs that address this are considered Bulletproof (or fool proof).

Each programming language (Java, C++, and C#) uses the same option for debugging a program. These are called Debuggers. While one can attempt to locate all bugs themselves, debuggers go through each line of code and display errors that they come across. Some debuggers will even attempt to correct the error for you.

Syntax Compilation errors are errors in a program are human errors around wording. This means that they occur due to the use of the incorrect spelling, wrong idiom, structure, or function. This can also occur if invalid equations are entered into a calculator, such as multiple decimal (.) points within a single number (Ex. $100.00.0).

Syntax errors only occur during compile-time and will halt the compilation of a program.

When Java experiences a Syntax Error during compilation, the compilation will halt and an error message will be displayed.

  1. /**
  2. * This is the Hello World program that is part of Lesson 2.
  3. */

  4. import com.otherwise.jurtle.*;

  5. public class HelloWorld extends Turtle
  6. {

  7. public void runTurtle()
  8. {
  9. // Print the message to the console.
  10. Console.println("Hello world!")
  11. }

  12. }

In this example, the semicolon was left off of the Console.println command (on line 13). Because of this, the compiler displayed the following Syntax Error:

HelloWorld.Java:13: ';' expected

Console.println("Hello world")

This shows where the error occurred within the code, and what was expected.

C++ and C# both work very much in the same fashion as Java in regards to this.

A Semantic error is also known as a logic error. This is a bug that causes one's program to behave incorrectly and producing inaccurate outputs. These types of errors usually don't cause the program to crash. These can be hard to find as most logic based programs have multiple paths to test. Somewhere along these paths, there is usually an incorrect formula, an error in the algorithm, or an incorrect algorithm.

Semantic Run-Time Errors are thrown when running a program, so they will not appear when compiling the program.

In C++, C#, and Java, these are handled in the same way, as Run-Time Errors will throw an Exception.

An example in C# is:

intResult = 10 / intSomeOtherVariable;

If a user were to enter 0 as the value, it would cause an infinite loop (as 0 can go into another number an infinite amount of times).

When the exception is thrown, it will stop the execution of the program.

References:

Jurtle Lessons: (http://www.otherwise.com/Lessons/index.html).

http://www.informit.com/library/content.aspx?b=STY_Csharp_24hours&seqNum=156


 

No comments:

Post a Comment