SlideShare une entreprise Scribd logo
1  sur  13
Error Handling

   In VB.net



                 1
Error Types
In VB.net errors fall into one of two main
categories:
 Syntax Errors
 Runtime Errors
 Logic Errors
Each type of error has a number of methods
which can help the programmer identify
and fix the problem. This process is called
Debugging.
                                              2
Syntax Errors
Syntax (or compiler) errors occur when you
write code that does not follow the rules of
the 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 Errors
Runtime errors are the result of code that
despite having the correct syntax, cannot be
executed.
 if not handled, will generate an exception, that
  will cause the program to halt.
This type of error is often caused by an
unexpected variable value e.g.
 missing or invisible
 wrong data type
Anticipate code that may result in runtime
errors and provide ways to avert crashes.
                                                     5
Debugging Runtime Errors
Using the debugger, accessed via the Debug menu
or 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 Errors
To prevent your program crashing - include
error-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
Validation
Any data input by the user should be validated
to prevent the program crashing
 If….Then…..Else




                                                 8
Activate Error-Trapping
Turn error-trapping on with a statement, so
that if the system generates an error, the
program 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-Trapping
The 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 Handling
A simpler method of Error-trapping is now
available 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 Handling
This method provides the option of trapping
various types of errors, and allows different
messages to be given for each one.
It also avoids jumping up and down the
procedure required by the On Error
(unstructured) Method




                                                12
Logic Errors
Logic Errors occur when the program
generates incorrect output or operates
incorrectly.
These errors can go unnoticed, and even
when they are detected, the source of the
error can be difficult to diagnose.
The only reliable method for identifying this
type of error is:
 Systematic and comprehensive Testing
 Check “expected output” against “actual output”
                                                    13

Contenu connexe

Tendances

Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling ConceptsVicter Paul
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validationMaitree Patel
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsAnil Kumar
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Salim M
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web ApplicationRishi Kothari
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling sharqiyem
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statementEyelean xilef
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in javaHitesh Kumar
 
Types of exceptions
Types of exceptionsTypes of exceptions
Types of exceptionsmyrajendra
 

Tendances (20)

Tracing in ASp.Net
Tracing in ASp.NetTracing in ASp.Net
Tracing in ASp.Net
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Event handling
Event handlingEvent handling
Event handling
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Input output streams
Input output streamsInput output streams
Input output streams
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
 
Java architecture
Java architectureJava architecture
Java architecture
 
Java features
Java featuresJava features
Java features
 
Java adapter
Java adapterJava adapter
Java adapter
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 
Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statement
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Types of exceptions
Types of exceptionsTypes of exceptions
Types of exceptions
 

Similaire à 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.pdfNALANDACSCCENTRE
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vbSalim M
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04Terry Yoast
 
Exception handling
Exception handlingException handling
Exception handlingRaja Sekhar
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Toolsgavhays
 
debuggingSession.pptx
debuggingSession.pptxdebuggingSession.pptx
debuggingSession.pptxmarawanwael
 
Debugging with NetBeans IDE
Debugging with NetBeans IDEDebugging with NetBeans IDE
Debugging with NetBeans IDEAndreas Ruppen
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction TechniquesKelly Bauer
 
Compiler design error handling
Compiler design error handlingCompiler design error handling
Compiler design error handlingRohitK71
 
UNIT-2-compiler design
UNIT-2-compiler designUNIT-2-compiler design
UNIT-2-compiler designkamaless4
 
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdfDifferent Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdfpCloudy
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in JavaAnkit Rai
 
Java Exception Handling and examples about it
Java Exception Handling and examples about itJava Exception Handling and examples about it
Java Exception Handling and examples about it2022002857mbit
 

Similaire à Debugging (20)

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
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vb
 
VBscript
VBscriptVBscript
VBscript
 
Debugging
DebuggingDebugging
Debugging
 
6-Error Handling.pptx
6-Error Handling.pptx6-Error Handling.pptx
6-Error Handling.pptx
 
Lecture 20-21
Lecture 20-21Lecture 20-21
Lecture 20-21
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
 
Exception handling
Exception handlingException handling
Exception handling
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Tools
 
Error handling
Error handlingError handling
Error handling
 
Maheen oop
Maheen oopMaheen oop
Maheen oop
 
debuggingSession.pptx
debuggingSession.pptxdebuggingSession.pptx
debuggingSession.pptx
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Debugging with NetBeans IDE
Debugging with NetBeans IDEDebugging with NetBeans IDE
Debugging with NetBeans IDE
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction Techniques
 
Compiler design error handling
Compiler design error handlingCompiler design error handling
Compiler design error handling
 
UNIT-2-compiler design
UNIT-2-compiler designUNIT-2-compiler design
UNIT-2-compiler design
 
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdfDifferent Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Java Exception Handling and examples about it
Java Exception Handling and examples about itJava Exception Handling and examples about it
Java Exception Handling and examples about it
 

Plus de nicky_walters (20)

Design documentation
Design documentationDesign documentation
Design documentation
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Software development lifecycle
Software development lifecycleSoftware development lifecycle
Software development lifecycle
 
Data structures vb
Data structures vbData structures vb
Data structures vb
 
Design for edp
Design for edpDesign for edp
Design for edp
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof language
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof language
 
Event driventheory
Event driventheoryEvent driventheory
Event driventheory
 
Simple debugging
Simple debuggingSimple debugging
Simple debugging
 
Simple debugging
Simple debuggingSimple debugging
Simple debugging
 
Using loops
Using loopsUsing loops
Using loops
 
Input output
Input outputInput output
Input output
 
Decisions
DecisionsDecisions
Decisions
 
Decisions
DecisionsDecisions
Decisions
 
Controls
ControlsControls
Controls
 
Decisions
DecisionsDecisions
Decisions
 

Debugging

  • 1. Error Handling In VB.net 1
  • 2. Error Types In VB.net errors fall into one of two main categories:  Syntax Errors  Runtime Errors  Logic Errors Each type of error has a number of methods which can help the programmer identify and fix the problem. This process is called Debugging. 2
  • 3. Syntax Errors Syntax (or compiler) errors occur when you write code that does not follow the rules of the language.  When the compiler recognises a syntax error, it marks the error with a blue wavy line. 3
  • 4. 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
  • 5. Runtime Errors Runtime errors are the result of code that despite having the correct syntax, cannot be executed.  if not handled, will generate an exception, that will cause the program to halt. This type of error is often caused by an unexpected variable value e.g.  missing or invisible  wrong data type Anticipate code that may result in runtime errors and provide ways to avert crashes. 5
  • 6. Debugging Runtime Errors Using the debugger, accessed via the Debug menu or 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
  • 7. Trapping Errors To prevent your program crashing - include error-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
  • 8. Validation Any data input by the user should be validated to prevent the program crashing  If….Then…..Else 8
  • 9. Activate Error-Trapping Turn error-trapping on with a statement, so that if the system generates an error, the program 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
  • 10. Activate Error-Trapping The 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
  • 11. Structured Exception Handling A simpler method of Error-trapping is now available 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
  • 12. Structured Exception Handling This method provides the option of trapping various types of errors, and allows different messages to be given for each one. It also avoids jumping up and down the procedure required by the On Error (unstructured) Method 12
  • 13. Logic Errors Logic Errors occur when the program generates incorrect output or operates incorrectly. These errors can go unnoticed, and even when they are detected, the source of the error can be difficult to diagnose. The only reliable method for identifying this type of error is:  Systematic and comprehensive Testing  Check “expected output” against “actual output” 13