• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Debugging
 

Debugging

on

  • 556 views

 

Statistics

Views

Total Views
556
Views on SlideShare
552
Embed Views
4

Actions

Likes
0
Downloads
8
Comments
0

1 Embed 4

http://moodle.wortech.ac.uk 4

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Debugging Debugging Presentation Transcript

    • Error Handling In VB.net 1
    • Error TypesIn VB.net errors fall into one of two maincategories: Syntax Errors Runtime Errors Logic ErrorsEach type of error has a number of methodswhich can help the programmer identifyand fix the problem. This process is calledDebugging. 2
    • Syntax ErrorsSyntax (or compiler) errors occur when youwrite code that does not follow the rules ofthe language. When the compiler recognises a syntax error, it marks the error with a blue wavy line. 3
    • Debugging Syntax Errors Moving the cursor over the marked code causes an error message to appear. Clicking on the error list, takes you directly to the offending line 4
    • Runtime ErrorsRuntime errors are the result of code thatdespite having the correct syntax, cannot beexecuted. if not handled, will generate an exception, that will cause the program to halt.This type of error is often caused by anunexpected variable value e.g. missing or invisible wrong data typeAnticipate code that may result in runtimeerrors and provide ways to avert crashes. 5
    • Debugging Runtime ErrorsUsing the debugger, accessed via the Debug menuor toolbar. Setting a breakpoint- pause the program at a particular line of code or when a variable changes value. Step Into - watch your program run line-by-line Rest the cursor over a variable to see its current value The Locals window - lists the current values of relevant variables (before the line is executed) The Watches window - choose program variable monitor, updated automatically as the program runs. The Command/Immediate window – try out commands or change the value of variables while the program is running. • Type “?” followed by a variable or expression to see its value • Use “=“ to assign a new value to a variable 6
    • Trapping ErrorsTo prevent your program crashing - includeerror-trapping statements in your code. Validate user input • If…..Then….Else….End If Activate error-trapping to correct the error • On Error GoTo Label…..Resume Use structured exception handling • Try….Catch….Finally Provide helpful error messages 7
    • ValidationAny data input by the user should be validatedto prevent the program crashing If….Then…..Else 8
    • Activate Error-TrappingTurn error-trapping on with a statement, sothat if the system generates an error, theprogram jumps to the code after the label. On Error GoTo Label Identify end of normal processing by adding “Exit Sub” just above End Sub Between Exit Sub and End Sub, place the Label indicated by adding a colon (:) Following the label, insert the code to correct the error. Finish with a “Resume” statement 9
    • Activate Error-TrappingThe Resume statement has the following options: Resume - Re-execute the statement that caused the problem Resume Next - Continue the code following the problem statement Resume Label2 – Go to the code following Label2 10
    • Structured Exception HandlingA simpler method of Error-trapping is nowavailable using the following format: Try • Statements that may cause an error Catch condition1 • Code if condition1 is true Catch condition2 • Code if condition2 is true Finally (optional) • Tidying-up statements (e.g. database error) End Try 11
    • Structured Exception HandlingThis method provides the option of trappingvarious types of errors, and allows differentmessages to be given for each one.It also avoids jumping up and down theprocedure required by the On Error(unstructured) Method 12
    • Logic ErrorsLogic Errors occur when the programgenerates incorrect output or operatesincorrectly.These errors can go unnoticed, and evenwhen they are detected, the source of theerror can be difficult to diagnose.The only reliable method for identifying thistype of error is: Systematic and comprehensive Testing Check “expected output” against “actual output” 13