SlideShare a Scribd company logo
Error-Handling and Debugging
• errors can be grouped into three categories:
       1. Syntax errors
       2. Run-time errors
       3. Logic errors
• Syntax errors occur when you mistype a command or leave out
  an expected phrase or argument.
• Visual Basic detects these errors as they occur and even
  provides help in correcting them.
• You cannot run a Visual Basic program until all syntax errors
  have been corrected.
• A syntax error (compiler error) is a programming mistake that
  violates the rules of Visual Basic, such as a misspelled
  property or keyword.
Error-Handling and Debugging

• Run-time errors are usually beyond your program's control.
  Examples include:
• when a variable takes on an unexpected value (divide by zero),
  when a drive door is left open, or when a file is not found. Visual
  Basic allows you to trap such errors and make attempts to correct
  them.
• Logic errors are the most difficult to find. With logic errors, the
  program will usually run, but will produce incorrect or unexpected
  results.
• A logic error is a human error — a programming mistake that makes
  the program code produce the wrong results
• The Visual Basic debugger is an aid in detecting logic errors.
•
Error-Handling and Debugging
• Some ways to minimize errors:
• Design your application carefully. More design time
  means less debugging time.
• Use comments where applicable to help you
  remember what you were trying to do.
• Use consistent and meaningful naming conventions
  for your variables, objects,and procedures.
Error-Handling and Debugging
• Run-Time Error Trapping and Handling
• Run-time errors are trappable.
• That is, Visual Basic recognizes an error has occurred
  and enables you to trap it and take corrective action.
• Error trapping is enabled with the On Error statement:
1. On Error GoTo label
2. On Error GoTo 0
3. On Error GoTo line#
4. On Error Resume Next
Error-Handling and Debugging
1. On Error GoTo label
• ddThe Visual Basic On Error GoTo statement is the
  foundation of handling trappable errors.
• When you execute an On Error GoTo Label statement
  in your code, execution is transferred to the code
  starting at Label if a trappable error has occurred.
Error-Handling and Debugging
• The best way to explain how to use error trapping is to look at
  an outline of an example procedure with error trapping.
      Sub SubExample()
      .       . [Declare variables, ...]
• .                   On Error GoTo HandleErrors
• .           . [Procedure code]
• .                          Exit Sub
              HandleErrors:
• .                          [Error handling code]
      End Sub
Error-Handling and Debugging
• Once you have set up the variable declarations, constant
  definitions, and any other procedure preliminaries, the On
  Error statement is executed to enable error trapping.
• Your normal procedure code follows this statement.
• The error handling code goes at the end of the procedure,
  following the HandleErrors statement label.
• This is the code that is executed if an error is encountered
  anywhere in the Sub procedure.
• Note you must exit (with Exit Sub) from the code before
  reaching the HandleErrors line to avoid inadvertent
  execution of the error handling code.
Error-Handling and Debugging
• On Error GoTo 0
• Since the error handling code is in the same procedure
  where an error occurs, all variables in that procedure are
  available for possible corrective action.
• If at some time in your procedure, you want to turn off
  error trapping, that is done with the following
  statement:On Error GoTo 0
• The Err object returns, in its Number property
  (Err.Number), the number associated with the current
  error condition.
• The Error() function takes this error number as its
  argument and returns a string description of the error.
Error-Handling and Debugging
• Once an error has been trapped and some action taken, control must be
  returned to your application.
• That control is returned via the Resume statement. There are three
  options:
• Resume                Lets you retry the operation that caused the
                        error. That is, control is returned to the line
                        where the error occurred. This could be
                        dangerous in that, if the error has not been
                        corrected (via code or by the user), an infinite
                        loop between the error handler and the
                        procedure code may result.
• Resume Next           Program control is returned to the line
                        immediately following the line where the error
                        occurred.
• Resume label        Program control is returned to the line labeled label.
Error-Handling and Debugging
• On Error Resume Next
• The On Error Resume Next statement provides an
  easy way to disregard errors, if you want to do so.
• Once you execute this statement, execution continues
  with the next line of code if the current line generates
  an error, and the error is disregarded.
Error-Handling and Debugging
• Debugging In Visual Basic
• Visual Basic offers a powerful suite of debugging options—
  notably the ability to single-step through your code as it’s
  executing.
• The standard way to debug is to place a breakpoint at a
  particular line in your code, and when execution reaches that
  line, it will halt and Visual Basic will enter the Debug state,
  giving you access to your code and variables.
• You can examine the contents of those variables and work
  through your code line by line, watching program execution
  behind the scenes.
• You place a breakpoint in code by moving the text insertion
  caret to that line and either selecting Toggle Breakpoint in the
  Debug menu or pressing F9.
Error-Handling and Debugging
• To move through your program step-by-step, you can
   select these stepping options in the Debug menu:
• Step Into—Single-step through the code, entering
                     called procedures if encountered.
• Step Over —Single-step through the code, stepping
              over procedure calls.
• Step Out— Step out of the current procedure.
Error-Handling and Debugging
• immediate window
• You can print directly to the immediate window while an
  application is running.
• Sometimes, this is all the debugging you may need. A few
  carefully placed print statements can sometimes clear up
  all logic errors, especially in small applications.
• To print to the immediate window, use the Print method:
• print[List of variables separated by commas or semi-
  colons]
• Eg: ?a;b or print a; b
Error-Handling and Debugging
• Locals Window
• The locals window shows the value of any variables
  within the scope of the current procedure.
• As execution switches from procedure to procedure,
  the contents of this window changes to reflect only
  the variables applicable to the current procedure.
• Repeat the above example and notice the values of A
  and B also appear in the locals window.
Error-Handling and Debugging
• Watch Expressions
• The Add Watch option on the Debug menu allows you to
  establish watch expressions for your application.
• Watch expressions can be variable values or logical
  expressions you want to view or test. Values of watch
  expressions are displayed in the watch window.
• In break mode, you can use the Quick Watch button on the
  toolbar to add watch expressions you need.
• Simply put the cursor on the variable or expression you want
  to add to the watch list and click the Quick Watch button.
• Watch expressions can be edited using the Edit Watch option
  on the Debug menu.
Error-Handling and Debugging
Error-Handling and Debugging
Error-Handling and Debugging

More Related Content

What's hot

Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Joins in dbms and types
Joins in dbms and typesJoins in dbms and types
Joins in dbms and types
university of Gujrat, pakistan
 
Operators
OperatorsOperators
Operators in java
Operators in javaOperators in java
Operators in java
AbhishekMondal42
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
Meghaj Mallick
 
Operators in java
Operators in javaOperators in java
Operators in java
Then Murugeshwari
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cyclemyrajendra
 
VB.NET:An introduction to Namespaces in .NET framework
VB.NET:An introduction to  Namespaces in .NET frameworkVB.NET:An introduction to  Namespaces in .NET framework
VB.NET:An introduction to Namespaces in .NET framework
Richa Handa
 
Visual Basic Controls ppt
Visual Basic Controls pptVisual Basic Controls ppt
Visual Basic Controls ppt
Ranjuma Shubhangi
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
C Programming: Structure and Union
C Programming: Structure and UnionC Programming: Structure and Union
C Programming: Structure and Union
Selvaraj Seerangan
 
java token
java tokenjava token
java token
Jadavsejal
 
11. transaction sql
11. transaction sql11. transaction sql
11. transaction sqlUmang Gupta
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
Jaya Kumari
 
Visual Basic 6.0
Visual Basic 6.0Visual Basic 6.0
Visual Basic 6.0
Anjan Mahanta
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
Anusha sivakumar
 

What's hot (20)

Interface in java
Interface in javaInterface in java
Interface in java
 
Joins in dbms and types
Joins in dbms and typesJoins in dbms and types
Joins in dbms and types
 
Operators
OperatorsOperators
Operators
 
Operators in java
Operators in javaOperators in java
Operators in java
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
VB.NET:An introduction to Namespaces in .NET framework
VB.NET:An introduction to  Namespaces in .NET frameworkVB.NET:An introduction to  Namespaces in .NET framework
VB.NET:An introduction to Namespaces in .NET framework
 
Visual Basic Controls ppt
Visual Basic Controls pptVisual Basic Controls ppt
Visual Basic Controls ppt
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
C Programming: Structure and Union
C Programming: Structure and UnionC Programming: Structure and Union
C Programming: Structure and Union
 
java token
java tokenjava token
java token
 
11. transaction sql
11. transaction sql11. transaction sql
11. transaction sql
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
 
Active x control
Active x controlActive x control
Active x control
 
Visual Basic 6.0
Visual Basic 6.0Visual Basic 6.0
Visual Basic 6.0
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
OOP java
OOP javaOOP java
OOP java
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
 

Similar to Error handling and debugging in vb

Debugging
DebuggingDebugging
Debugging
Ajeng Savitri
 
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdfVISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
NALANDACSCCENTRE
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
Appili Vamsi Krishna
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
ssusere336f4
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
iamluqman0403
 
Exception handling
Exception handlingException handling
Exception handling
pooja kumari
 
Unit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartUnit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and Flowchart
Bom Khati
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle
Frankie Jones
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
Mani Kandan
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptx
shoaibkhan716300
 
Error Detection & Recovery.pptx
Error Detection & Recovery.pptxError Detection & Recovery.pptx
Error Detection & Recovery.pptx
MohibKhan79
 
Debugging MAD lecture june .pptx
Debugging MAD lecture june .pptxDebugging MAD lecture june .pptx
Debugging MAD lecture june .pptx
ArishaNaz2
 
Lecture 3.1.1 Try Throw Catch.pptx
Lecture 3.1.1 Try Throw Catch.pptxLecture 3.1.1 Try Throw Catch.pptx
Lecture 3.1.1 Try Throw Catch.pptx
sunilsoni446112
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
Akhil Kaushik
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
MIT,Imphal
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
MaqdamYasir
 
Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)
Thapar Institute
 

Similar to Error handling and debugging in vb (20)

Debugging
DebuggingDebugging
Debugging
 
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdfVISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
Debugging
DebuggingDebugging
Debugging
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
 
Exception handling
Exception handlingException handling
Exception handling
 
Unit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and FlowchartUnit 3.1 Algorithm and Flowchart
Unit 3.1 Algorithm and Flowchart
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptx
 
Error Detection & Recovery.pptx
Error Detection & Recovery.pptxError Detection & Recovery.pptx
Error Detection & Recovery.pptx
 
Debugging MAD lecture june .pptx
Debugging MAD lecture june .pptxDebugging MAD lecture june .pptx
Debugging MAD lecture june .pptx
 
Lecture 3.1.1 Try Throw Catch.pptx
Lecture 3.1.1 Try Throw Catch.pptxLecture 3.1.1 Try Throw Catch.pptx
Lecture 3.1.1 Try Throw Catch.pptx
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
F6dc1 session6 c++
F6dc1 session6 c++F6dc1 session6 c++
F6dc1 session6 c++
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)
 

Recently uploaded

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 

Error handling and debugging in vb

  • 1. Error-Handling and Debugging • errors can be grouped into three categories: 1. Syntax errors 2. Run-time errors 3. Logic errors • Syntax errors occur when you mistype a command or leave out an expected phrase or argument. • Visual Basic detects these errors as they occur and even provides help in correcting them. • You cannot run a Visual Basic program until all syntax errors have been corrected. • A syntax error (compiler error) is a programming mistake that violates the rules of Visual Basic, such as a misspelled property or keyword.
  • 2. Error-Handling and Debugging • Run-time errors are usually beyond your program's control. Examples include: • when a variable takes on an unexpected value (divide by zero), when a drive door is left open, or when a file is not found. Visual Basic allows you to trap such errors and make attempts to correct them. • Logic errors are the most difficult to find. With logic errors, the program will usually run, but will produce incorrect or unexpected results. • A logic error is a human error — a programming mistake that makes the program code produce the wrong results • The Visual Basic debugger is an aid in detecting logic errors. •
  • 3. Error-Handling and Debugging • Some ways to minimize errors: • Design your application carefully. More design time means less debugging time. • Use comments where applicable to help you remember what you were trying to do. • Use consistent and meaningful naming conventions for your variables, objects,and procedures.
  • 4. Error-Handling and Debugging • Run-Time Error Trapping and Handling • Run-time errors are trappable. • That is, Visual Basic recognizes an error has occurred and enables you to trap it and take corrective action. • Error trapping is enabled with the On Error statement: 1. On Error GoTo label 2. On Error GoTo 0 3. On Error GoTo line# 4. On Error Resume Next
  • 5. Error-Handling and Debugging 1. On Error GoTo label • ddThe Visual Basic On Error GoTo statement is the foundation of handling trappable errors. • When you execute an On Error GoTo Label statement in your code, execution is transferred to the code starting at Label if a trappable error has occurred.
  • 6. Error-Handling and Debugging • The best way to explain how to use error trapping is to look at an outline of an example procedure with error trapping. Sub SubExample() . . [Declare variables, ...] • . On Error GoTo HandleErrors • . . [Procedure code] • . Exit Sub HandleErrors: • . [Error handling code] End Sub
  • 7. Error-Handling and Debugging • Once you have set up the variable declarations, constant definitions, and any other procedure preliminaries, the On Error statement is executed to enable error trapping. • Your normal procedure code follows this statement. • The error handling code goes at the end of the procedure, following the HandleErrors statement label. • This is the code that is executed if an error is encountered anywhere in the Sub procedure. • Note you must exit (with Exit Sub) from the code before reaching the HandleErrors line to avoid inadvertent execution of the error handling code.
  • 8. Error-Handling and Debugging • On Error GoTo 0 • Since the error handling code is in the same procedure where an error occurs, all variables in that procedure are available for possible corrective action. • If at some time in your procedure, you want to turn off error trapping, that is done with the following statement:On Error GoTo 0 • The Err object returns, in its Number property (Err.Number), the number associated with the current error condition. • The Error() function takes this error number as its argument and returns a string description of the error.
  • 9. Error-Handling and Debugging • Once an error has been trapped and some action taken, control must be returned to your application. • That control is returned via the Resume statement. There are three options: • Resume Lets you retry the operation that caused the error. That is, control is returned to the line where the error occurred. This could be dangerous in that, if the error has not been corrected (via code or by the user), an infinite loop between the error handler and the procedure code may result. • Resume Next Program control is returned to the line immediately following the line where the error occurred. • Resume label Program control is returned to the line labeled label.
  • 10. Error-Handling and Debugging • On Error Resume Next • The On Error Resume Next statement provides an easy way to disregard errors, if you want to do so. • Once you execute this statement, execution continues with the next line of code if the current line generates an error, and the error is disregarded.
  • 11. Error-Handling and Debugging • Debugging In Visual Basic • Visual Basic offers a powerful suite of debugging options— notably the ability to single-step through your code as it’s executing. • The standard way to debug is to place a breakpoint at a particular line in your code, and when execution reaches that line, it will halt and Visual Basic will enter the Debug state, giving you access to your code and variables. • You can examine the contents of those variables and work through your code line by line, watching program execution behind the scenes. • You place a breakpoint in code by moving the text insertion caret to that line and either selecting Toggle Breakpoint in the Debug menu or pressing F9.
  • 12. Error-Handling and Debugging • To move through your program step-by-step, you can select these stepping options in the Debug menu: • Step Into—Single-step through the code, entering called procedures if encountered. • Step Over —Single-step through the code, stepping over procedure calls. • Step Out— Step out of the current procedure.
  • 13. Error-Handling and Debugging • immediate window • You can print directly to the immediate window while an application is running. • Sometimes, this is all the debugging you may need. A few carefully placed print statements can sometimes clear up all logic errors, especially in small applications. • To print to the immediate window, use the Print method: • print[List of variables separated by commas or semi- colons] • Eg: ?a;b or print a; b
  • 14. Error-Handling and Debugging • Locals Window • The locals window shows the value of any variables within the scope of the current procedure. • As execution switches from procedure to procedure, the contents of this window changes to reflect only the variables applicable to the current procedure. • Repeat the above example and notice the values of A and B also appear in the locals window.
  • 15. Error-Handling and Debugging • Watch Expressions • The Add Watch option on the Debug menu allows you to establish watch expressions for your application. • Watch expressions can be variable values or logical expressions you want to view or test. Values of watch expressions are displayed in the watch window. • In break mode, you can use the Quick Watch button on the toolbar to add watch expressions you need. • Simply put the cursor on the variable or expression you want to add to the watch list and click the Quick Watch button. • Watch expressions can be edited using the Edit Watch option on the Debug menu.