Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Week 10

Debugging and Tracing


PF101 - Object Oriented Programming
LESSON 8 – DEBUGGING AND TRACING

At the end of the session, the students should be


able to:
1. Define VB Classes and Objects
2. Explain File Handling
3. Identify different error handling

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 2
Week 10– DEBUGGING AND TRACING

Classes
• A class groups different functions, methods,
variables, and properties, which are called its
members.
• A class encapsulates the members, which
can be accessed by an instance of the class,
called an object. Classes are the building
blocks of object-oriented programming
languages.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 3
Week 10– DEBUGGING AND TRACING

Abstract Class
• If classes share common
functionality you can group this in a
base or abstract class. Abstract
classes can contain partial or no
implementation at all and allow the
derived type to override the base
implementation.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 4
Week 10– DEBUGGING AND TRACING

A sub type can then inherit this abstract class as shown below:

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 5
Week 10– DEBUGGING AND TRACING

Car will inherit all of the declared types within vehicle, but
can only access them based upon the underlying access
modifier.

In the above example a new Car instance is created. The


DisplayWheelCount() method is then invoked which will
call the base class Vehicles implementation.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 6
Week 10– DEBUGGING AND TRACING

Creating Classes
• Classes provide a way of creating your own
types within the .NET framework. Within a
class definition you may include the
following:
• Fields
• Properties
• Methods
• Constructors
• Events

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 7
Week 10– DEBUGGING AND TRACING
To declare a class you use the following syntax:

Other .NET types can be encapsulated within the class and


exposed accordingly, as shown below:

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 8
Week 10– DEBUGGING AND TRACING

Object
• Object is a self-contained component that
contains properties and methods needed to
make a certain type of data useful.

• A class is a blueprint or template or set of


instructions to build a specific type of object. Every
object is built from a class. Each class should be
designed and programmed to accomplish one, and
only one, thing.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 9
Week 10– DEBUGGING AND TRACING

Finding and Correcting Errors


Errors
• Errors or mistakes in a program are often referred
to as bugs. They are almost always the fault of the
programmer. The process of finding and eliminating
errors is called debugging. Errors can be classified
into three major groups:
• Syntax errors
• Runtime errors
• Logical errors

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 10
Week 10– DEBUGGING AND TRACING

Three Types of Errors


• Three types of errors can occur in a Visual Basic
program: syntax errors, run-time errors, and logic
errors, as follows:
• A syntax error (or compiler error) is a mistake
(such as a misspelled property or keyword) that
violates the programming rules of Visual Basic.
Visual Basic will point out several types of syntax
errors in your programs while you enter program
statements, and it won’t let you run a program until
you fix each syntax error.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 11
Week 10– DEBUGGING AND TRACING
• A run-time error is a mistake that causes a program to
stop unexpectedly during execution. Run-time errors
occur when an outside event or an undiscovered syntax
error forces a program to stop while it’s running. For
instance, if you misspell a file name when you use the
System. Drawing.Image. FromFile method, or if you try to
read a disk drive and it doesn’t contain a CD or DVD, your
code will generate a run-time error.
• A logic error is a human error—a mistake that causes the
program code to produce the wrong results. Most
debugging efforts are focused on tracking down logic
errors introduced by the programmer.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 12
Week 10– DEBUGGING AND TRACING

Finding and Correcting Error (Identifying


Syntax Errors)
• VB.Net will find these kinds of errors when it tries
to parse your program, and exit with an error
message without running anything. Syntax errors
are mistakes in the use of the Visual Basic language,
and are analogous to spelling or grammar mistakes
in a language like English: for example, the
sentence Would you some tea? does not make
sense – it is missing a verb.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 13
Week 10– DEBUGGING AND TRACING

Finding and Correcting Error (Identifying Run-


time Errors)
• If a program is syntactically correct – that is, free of
syntax errors – it will be run by the Python
interpreter. However, the program may exit
unexpectedly during execution if it encounters
a runtime error – a problem which was not
detected when the program was parsed, but is only
revealed when a particular line is executed. When a
program comes to a halt because of a runtime
error, we say that it has crashed.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 14
Week 10– DEBUGGING AND TRACING

Finding and Correcting Error (Identifying Logic


Errors)
• Logic errors in your programs are often
the most difficult to fix. It is the result of
faulty reasoning and planning, not a
misunderstanding about Visual Basic
syntax.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 15
Week 10– DEBUGGING AND TRACING

Error Handling – Try, Catch, Finally Statement


• Structure

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 16
Week 10– DEBUGGING AND TRACING
• Example Code

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 17
Week 10– DEBUGGING AND TRACING

Debugging 101: Using Debugging Mode


• One way to identify a logic error is to execute your
program code one line at a time and examine the
content of one or more variables or properties as
they change. To do this, you can enter debugging
mode (or break mode) while your program is
running and then view your code in the Code
Editor. Debugging mode gives you a close-up look at
your program while the Visual Basic compiler is
executing it. You’ll then use debugging mode to find
and correct the logic error you discovered.

PF101 - OBJECT ORIENTED PROGRAMMING


PF101 – Object Oriented Programming 18
PF101 - OBJECT ORIENTED PROGRAMMING 19

You might also like