Types Of Errors In Best Programming's

Errors:

Errors

Types of Errors

Different types of errors can occur in C++ programs.

Types of Errors

  • Syntax Error
  • Logical Error
  • Run-Time Error 

Syntax Errors

A collection of rules for writing programs in a programming language is known as syntax. All program statements must be written according to the syntax. A syntax error is a type of error that occurs when a statement violates the syntax. The compiler detects syntax error and display error message to describe the cause of error. A program containing syntax errors cannot be compiled successfully.

Syntax Errors

Some important causes of syntax errors are as follows:

  • The statement terminator is missing at the end of statement.
  • A keyword is misspelled.
  • Any of the delimiters is missing.

Example:

Typing cout instead of coutt is an example of syntax error.

Logical Errors

A type of error that occurs due to poor logic of the programmer is called logical error A statement with logical error may produce unexpected and wrong results in the program The logical errors are difficult to find because the translator cannot detect these errors. The logical errors can only be detected by examining the program thoroughly.

Logical Errors

Different causes of logical errors are as follows:

  • Using wrong conditions in program such as writing a < 5 instead of a > 5.
  • Using wrong formula in the program such as writing Average= Total * 5 instead of Average=Total /5

Logical error is the most difficult type of error for the following reasons:

  • It cannot be detected by the compiler.
  • It does not crash the program. That is why it is difficult to detect The user needs to review the whole program to find out logical error.
  • It may take a lot of time for detecting logical error.

Run-Time Errors

A type of error that occurs during the execution of program is called run-time error. It is caused when a statement directs the computer to execute an illegal operation such as dividing a number by zero.

Run-Time Errors

The run-time errors are detected and displayed by the computer during execution. Run-time errors are normally caused due to wrong input from the user. The computer stops executing the program and displays the error message if a runtime error occurs.

Example:

The user may ask the program to open a file that does not exist or the user may enter wrong type of data. etc,

Debugging in Turbo C++

An error in a computer program is known as bug. The process of finding and removing bugs is known as debugging then debugging in Turbo C++.

Debugging Features of Turbo C++

Turbo C++ provides many useful debugging features. The debugging features are available in Debug menu Some important debugging features of Turbo C++ are as follows:

Single Stepping

A program may not execute even if it has been compiled successfully. The debugger provides the facility to find errors by executing one line of the program at one time. It enables the programmer to detect the exact place of error.

The following procedure is used to execute one step at a time with single stepping:

  • Select Run > Trace Into OR press F7

Watches

The watch or watch expression is used to check the value of a variable as the program executes. It indicates how the values of variables change during program execution. It is normally used in combination with single stepping.

The following procedure is used for watch or watch expression:

  • Place the cursor on the variable whose value is to be checked.
  • Select Debug > Watches A submenu will appear.
  • Select Add Watch from the submenu OR press CTRL+F7 A dialog box will appear The selected variable will appear in Watch expression field.
  • Click OK OR press Enter A new window will appear indicating that the selected symbol is undefined.
  • Select Run > Trace Into OR press F7 to execute single stepping. The value of the selected variable will appear in Watch window.

Breakpoints

A breakpoint is used to mark a part of program where program execution will stop. The program executes all statements up to the breakpoint and then stops. The user can check the values of a variable at this point by using. Watch window by single stepping remaining part of the program.


The following procedure is used to insert a breakpoint in the program:

  • Place the cursor on the line on which the breakpoint is to be inserted.
  • Select Debug > Toggle breakpoint OR press CTRL+F8. The breakpoint will be inserted and the line will be highlighted.

Evaluate/Modify Window

The evaluate/modify window is used to change the value of variable during program execution. It can be useful if the user is single stepping the program and wants to change the value of a certain variable.

The following procedure is used to use evaluate/modify window:

  • Select Debug > Evaluate/Modify A new window will appear with three fields.
  • Enter the name of the variable whose value is to be modified in Expression field.
  • Enter the new value for the variable in New Value field The value of the third field.

Result will also change automatically.

Post a Comment

0 Comments