Errors & Error Trapping. Types of Errors Syntax - violate language rules Semantic - violate usage rules of language Run-time – occur while program is

  • View
    218

  • Download
    4

Embed Size (px)

Text of Errors & Error Trapping. Types of Errors Syntax - violate language rules Semantic - violate usage...

  • Slide 1
  • Errors & Error Trapping
  • Slide 2
  • Types of Errors Syntax - violate language rules Semantic - violate usage rules of language Run-time occur while program is running Logic incorrect algorithm
  • Slide 3
  • Syntax Errors E.g. If X > 0 And < 10 Then E.g. me.Cls() Trapped by Compiler Must be corrected before program will compile
  • Slide 4
  • Syntax Errors E.g. If X > 0 And < 10 Then E.g. me.Cls() Trapped by Compiler Must be corrected before program will compile Incorrect specification of logical expression Misspelled name
  • Slide 5
  • Syntax Errors E.g. Dim x As String For x = 1 To 10 Statements to be repeated 10 times Next x Trapped by Compiler Must be corrected before program will compile
  • Slide 6
  • Syntax Errors E.g. Dim x As String For x = 1 To 10 Statements to be repeated 10 times Next x Trapped by Compiler Must be corrected before program will compile For loop control variable must be integer or long
  • Slide 7
  • Semantic Errors E.g. Dim x As Integer, Start As Integer, Finish As Integer Start = 10 Finish = 0 For x = Start To Finish Statements to be repeated 10 times Next x Trapped by testing
  • Slide 8
  • Semantic Errors E.g. Dim x As Integer, Start As Integer, Finish As Integer Start = 10 Finish = 0 For x = Start To Finish Statements to be repeated 10 times Next x Trapped by testing Start must be < Finish else, loop will not run
  • Slide 9
  • Run-time Errors(exceptions) E.g. DC = File.OpenText(Myfile.text) E.g. Dim FileName As String FileName = txtFileName.Text DC = File.OpenText(FileName) Trapped by run-time system
  • Slide 10
  • Run-time Errors(exceptions) E.g. DC = File.OpenText(Myfile.text) E.g. Dim FileName As String FileName = txtFileName.Text DC = File.OpenText(FileName) Trapped by run-time system Bad extension Non-existent path or filename
  • Slide 11
  • Run-time Errors(exceptions) E.g. Dim Value As Single Value = txtValue.Text
  • Slide 12
  • Run-time Errors(exceptions) E.g. Dim Value As Single Value = txtValue.Text Program will crash if txtValue is empty
  • Slide 13
  • Logic Errors E.g. to calculate the average of First and Second Average = First + Second / 2 Program will run but produce incorrect results Trapped only by testing (recommended) or users noticing incorrect results (unreliable)
  • Slide 14
  • Logic Errors E.g. Average = First + Second / 2 Program will run but produce incorrect results Trapped only by testing or users noticing incorrect results Correct statement is Average = (First + Second) / 2
  • Slide 15
  • Logic Errors E.g. Function IsCapital (Letter As Char) Boolean If Letter > A And Letter < Z Then Return True Else Return False End If End Function Program will run but produce incorrect results Trapped only by testing or users noticing incorrect results
  • Slide 16
  • Logic Errors E.g. Function IsCapital (Letter As Char) Boolean If Letter > A And Letter < Z Then Return True Else Return False End If End Function Program will run but produce incorrect results Trapped only by testing or users noticing incorrect results It will return False for A and Z Use >= and
  • Logic Errors E.g. Function IsLetter (Ascii As Char) Boolean If (Ascii >= A And Ascii = a And Ascii
  • Logic Errors E.g. Function IsLetter (Ascii As Char) Boolean If (Ascii >= A And Ascii = a And Ascii