SlideShare a Scribd company logo
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

More Related Content

What's hot

Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
prabhu rajendran
 
Java Networking
Java NetworkingJava Networking
Java Networking
Sunil OS
 
Debugging
DebuggingDebugging
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Components of .NET Framework
Components of .NET FrameworkComponents of .NET Framework
Components of .NET Framework
Roshith S Pai
 
Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
prabhu rajendran
 
Visual Basic Controls ppt
Visual Basic Controls pptVisual Basic Controls ppt
Visual Basic Controls ppt
Ranjuma Shubhangi
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
Data management with ado
Data management with adoData management with ado
Data management with adoDinesh kumar
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51myrajendra
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
priya Nithya
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
suraj pandey
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
Guddu gupta
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
Mohammed Abdalla Youssif
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
Jalpesh Vasa
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 

What's hot (20)

Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Vb.net ide
Vb.net ideVb.net ide
Vb.net ide
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Debugging
DebuggingDebugging
Debugging
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Components of .NET Framework
Components of .NET FrameworkComponents of .NET Framework
Components of .NET Framework
 
Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
 
C# basics
 C# basics C# basics
C# basics
 
Visual Basic Controls ppt
Visual Basic Controls pptVisual Basic Controls ppt
Visual Basic Controls ppt
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Data management with ado
Data management with adoData management with ado
Data management with ado
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 

Similar to 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
NALANDACSCCENTRE
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vb
Salim M
 
VBscript
VBscriptVBscript
VBscript
vikashraj2090
 
Error Handling in Compiler Design.doctyp
Error Handling in Compiler Design.doctypError Handling in Compiler Design.doctyp
Error Handling in Compiler Design.doctyp
BhuvaneswariR27
 
Error Handling in Compiler Design.What a
Error Handling in Compiler Design.What aError Handling in Compiler Design.What a
Error Handling in Compiler Design.What a
BhuvaneswariR27
 
Error Handling in Compiler Design.typeso
Error Handling in Compiler Design.typesoError Handling in Compiler Design.typeso
Error Handling in Compiler Design.typeso
BhuvaneswariR27
 
Debugging
DebuggingDebugging
Debugging
Ajeng Savitri
 
6-Error Handling.pptx
6-Error Handling.pptx6-Error Handling.pptx
6-Error Handling.pptx
amiralicomsats3
 
Lecture 20-21
Lecture 20-21Lecture 20-21
Lecture 20-21
talha ijaz
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
Terry Yoast
 
Exception handling
Exception handlingException handling
Exception handling
Raja Sekhar
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Toolsgavhays
 
Error handling
Error handlingError handling
Error handling
Meherul1234
 
Maheen oop
Maheen oopMaheen oop
Maheen oop
mahshah212
 
debuggingSession.pptx
debuggingSession.pptxdebuggingSession.pptx
debuggingSession.pptx
marawanwael
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
siragezeynu
 
Debugging with NetBeans IDE
Debugging with NetBeans IDEDebugging with NetBeans IDE
Debugging with NetBeans IDE
Andreas Ruppen
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction Techniques
Kelly Bauer
 
Compiler design error handling
Compiler design error handlingCompiler design error handling
Compiler design error handling
RohitK71
 
UNIT-2-compiler design
UNIT-2-compiler designUNIT-2-compiler design
UNIT-2-compiler design
kamaless4
 

Similar to 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
 
Error Handling in Compiler Design.doctyp
Error Handling in Compiler Design.doctypError Handling in Compiler Design.doctyp
Error Handling in Compiler Design.doctyp
 
Error Handling in Compiler Design.What a
Error Handling in Compiler Design.What aError Handling in Compiler Design.What a
Error Handling in Compiler Design.What a
 
Error Handling in Compiler Design.typeso
Error Handling in Compiler Design.typesoError Handling in Compiler Design.typeso
Error Handling in Compiler Design.typeso
 
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
 

More from 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