SlideShare a Scribd company logo
1 of 30
Exception Handling and Debugging
Objectives
In this lesson, you will learn to:
Identify the mechanism to handle run time errors
Differentiate between structured and unstructured exception
       handling
Handle exceptions
Debug an application




   ©NIIT               Exception Handling and Debugging/Lesson 11/Slide 1 of 30
Exception Handling and Debugging
Problem Statement 11.D.1
While executing the application for adding order details, if the
server returns an error or there is insufficient memory to
execute the application, an appropriate message should be
displayed and the application should not terminate abruptly.




   ©NIIT              Exception Handling and Debugging/Lesson 11/Slide 2 of 30
Exception Handling and Debugging
Task List
Identify the mechanism to handle errors.
Write the code to handle errors.
Execute the application to verify the results of exception
handling.




   ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 3 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to handle errors.
An exception is termed as an abnormal condition
encountered by an application during execution.
Exception handling
     Is the process of providing an alternate path to be
      executed when the application is unable to execute in
      the desired way.




   ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 4 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to handle errors.
(Contd.)
Structured exception handling
    All the exceptions are derived from the
     System.Exception class.
             System.Exception




                   System.ApplicationException


                   System.Windows.Forms.AxHost.InvalidActiveXStateException


                   System.Runtime.Remoting.MetadataServices.SUDSParserException


                   System.IO.IsolatedStorage.IsolatedStorageException



                   System.Runtime.Remoting.MetadataServices.SUDSGeneratorException


                   System.SystemException



  ©NIIT                   Exception Handling and Debugging/Lesson 11/Slide 5 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to handle errors.
(Contd.)
 Structured exception handling (Contd.)
            Divides an application into blocks of code that have
             the probability of raising an error.
            Uses the Try…Catch…Finally statement.
            Errors are filtered in the Catch block.




   ©NIIT                Exception Handling and Debugging/Lesson 11/Slide 6 of 30
Exception Handling and Debugging
Just a Minute…
In the Try…Catch…Finally statement, when is the code
given in each of the blocks executed?




  ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 7 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to handle errors.
(Contd.)
User-defined exceptions
    Can be created by deriving a class from the
     ApplicationException class.
Unstructured exception handling
    Is done by placing an On Error statement in a block of
     code.
    Uses the On Error GoTo statement to pass the control
     to a specific error handler when an error occurs.
    Uses the On Error Resume Next statement to pass
     control to the next executable statement when an error
     occurs.
    Uses the On Error GoTo 0 to disable an error handler.
  ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 8 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to handle errors.
(Contd.)
Result:
Since unstructured exception handling code is difficult to
maintain, you will use structured exception handling to trap
 and handle errors for the given problem statement.




   ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 9 of 30
Exception Handling and Debugging
Just a Minute…
What is the difference between the On Error GoTo 0, On
Error Resume Next, and On Error GoTo ErrorHandler
statements and when is each of them used?




   ©NIIT          Exception Handling and Debugging/Lesson 11/Slide 10 of 30
Exception Handling and Debugging
Task 2: Write the code to handle errors.
Task 3: Execute the application to verify the results
of exception handling.




  ©NIIT           Exception Handling and Debugging/Lesson 11/Slide 11 of 30
Exception Handling and Debugging
Problem Statement 11.P.1
A weekly order details report and a weekly query handling
report have been created. Based on the user’s choice, the
corresponding report should be displayed. If the report to be
opened gives a loading error, an appropriate message should
be displayed and the application should not end abruptly.




   ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 12 of 30
Exception Handling and Debugging
Problem Statement 11.D.2
An application has been created to display the product ID for a
product that costs more than $3000.
A Windows Form has been designed with a ListBox control
and a Button control.
A data adapter has been created and the Base_Cost and
ProdID columns of the table Product have been retrieved. A
dataset has been generated for the data adapter.
The code has been written for the Load event of the form to
display the ProductID for the products with cost more than
$3000 in the list box.
However, the application does not give the expected output.
The list box displays one product ID multiple times.
   ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 13 of 30
Exception Handling and Debugging
Task List
Identify the mechanism to trap the error.
Identify the starting point to search for errors.
Implement error trapping.
Run the application and trace the error.
Rectify the code.
Verify the output of the code.




   ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 14 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to trap the error.
Tracing and rectifying an error is termed as debugging.
In order to assist you in debugging logical and run-time
errors, Visual Basic .NET provides extensive debugging
tools. You can access these tools by using:
     Debug toolbar
     Debug menu




   ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 15 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to trap the error.
(Contd.)
In an application, by using the debugging tools, you can:
    Start execution
    Break execution
    Stop execution
Result:
You will use the debugging tools provided by Visual
Studio .NET to trap and rectify the error.




   ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 16 of 30
Exception Handling and Debugging
Task 2:Identify the starting point to search for errors.
Result:
Since the list box contains a product ID, it indicates that
there is no error in the database connection. The error trap
        should be set starting from the line containing
OleDbDAProduct.Fill(DsProduct1)command as the
        error occurs after the connection is opened.
Task 3: Implement error trapping.
Task 4: Run the application and trace the error.
Two options in the Debug menu to start an application:
    The Start option
    The Start Without Debugging option
   ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 17 of 30
Exception Handling and Debugging
Task 4: Run the application and trace the error.
(Contd.)
You may select the Debug menu option and select any of
 the following, to instruct Visual Basic .NET regarding the
 execution of the code.
    Step Into
    Step Over
    Step Out

Task 5: Rectify the code.
Task 6: Verify the output of the code.


   ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 18 of 30
Exception Handling and Debugging
Problem Statement 11.D.3
An application has been developed to connect to the database
and retrieve customer details from the database. The code
has been added in the Load event of the form, which will
display customer details.
However, the application generates an error, as it is not able
to connect to the database.




   ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 19 of 30
Exception Handling and Debugging
Task List
Identify the mechanism to debug the code.
Implement debugging.
Rectify the code.
Verify the output of the code.




   ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 20 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to debug the code.
Visual Basic provides you with some tools to debug your
 application during the break mode. Two of the debugging
 tools are listed below:
     The Locals window
     The Immediate window
Result:
As per the problem statement, the connection with the
database server has failed. The connection to the database
  is being made with the help of variables that form part of the
  connection string. The connection to the database can fail if
  the values in the variables are not correct.
  To solve this problem, you need to use the Immediate
window to see the value that the user enters and is stored in
the variable db.
   ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 21 of 30
Exception Handling and Debugging
Task 2: Implement debugging.
Task 3: Rectify the code.
Task 4: Verify the output of the code.




  ©NIIT          Exception Handling and Debugging/Lesson 11/Slide 22 of 30
Exception Handling and Debugging
Problem Statement 11.D.4
An application has been developed which displays the
corresponding base cost and the product name of the product
ID selected by the user from a list box. The general level
declarations have been made and the code has been added.
However, the application displays the product name and the
base cost of the product ID P014 regardless of the ID selected
by the user.




   ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 23 of 30
Exception Handling and Debugging
Task List
Identify the mechanism to debug the code.
Implement debugging.
Rectify the code.
Verify the output of the code.




   ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 24 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to debug the code.
The following windows are used for debugging an
application:
    Watch window
    Call Stack window
    The Output window




  ©NIIT           Exception Handling and Debugging/Lesson 11/Slide 25 of 30
Exception Handling and Debugging
Task 1: Identify the mechanism to debug the code.
(Contd.)
Result:
Since the variable prodid stores the selected item, its value
      has to be traced. Therefore, you will use the Watch
window       to trace the behavior of prodid.
Task 2: Implement debugging.
Task 3: Rectify the code.
Task 4: Verify the output of the code.




   ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 26 of 30
Exception Handling and Debugging
Summary
In this lesson, you learned that:
The types of errors that can occur in an application are
syntax errors, run-time errors, and logical errors.
An exception is an abnormal or condition that an application
      encounters during execution.
Exception handling is the process of providing an alternate
     path to be executed when the application is not able to
     execute in the desired way.




    ©NIIT             Exception Handling and Debugging/Lesson 11/Slide 27 of 30
Exception Handling and Debugging
Summary (Contd.)
Visual Basic .NET provides two methods to handle
exceptions:
    Structured exception handling
    Unstructured exception handling
In order to assist you in debugging logical and runtime
errors, Visual Basic .NET provides extensive debugging
tools. You can use the Visual Basic .NET Debug toolbar to
access these tools.




   ©NIIT            Exception Handling and Debugging/Lesson 11/Slide 28 of 30
Exception Handling and Debugging
Summary (Contd.)
By using the debugging tools, you can perform the following
      actions:
    Start execution
    Break execution
           ® Whilein break mode, the following windows can be
            used to trace and debug an application:
              ® Call   Stack window
              ® Watch    window
              ® Locals   window
              ® Immediate     window

   ©NIIT                  Exception Handling and Debugging/Lesson 11/Slide 29 of 30
Exception Handling and Debugging
Summary (Contd.)
          ® Output   window
   Step through execution
   Stop execution




  ©NIIT              Exception Handling and Debugging/Lesson 11/Slide 30 of 30

More Related Content

Viewers also liked

Vb.net session 05
Vb.net session 05Vb.net session 05
Vb.net session 05Niit Care
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controlsGuddu gupta
 
Procedures functions structures in VB.Net
Procedures  functions  structures in VB.NetProcedures  functions  structures in VB.Net
Procedures functions structures in VB.Nettjunicornfx
 
Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual BasicSangeetha Sg
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vbSalim M
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NETrchakra
 
Validation controls ppt
Validation controls pptValidation controls ppt
Validation controls pptIblesoft
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in aspShishir Jain
 
structured and unstructured interview
structured and unstructured interviewstructured and unstructured interview
structured and unstructured interviewahsan mubeen
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programmingRoger Argarin
 

Viewers also liked (17)

Vb.net session 05
Vb.net session 05Vb.net session 05
Vb.net session 05
 
Decisions
DecisionsDecisions
Decisions
 
Simple debugging
Simple debuggingSimple debugging
Simple debugging
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
Procedures functions structures in VB.Net
Procedures  functions  structures in VB.NetProcedures  functions  structures in VB.Net
Procedures functions structures in VB.Net
 
Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual Basic
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vb
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
Validation controls ppt
Validation controls pptValidation controls ppt
Validation controls ppt
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in asp
 
Exception handling
Exception handlingException handling
Exception handling
 
structured and unstructured interview
structured and unstructured interviewstructured and unstructured interview
structured and unstructured interview
 
Structured Interviews
Structured InterviewsStructured Interviews
Structured Interviews
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
 

Similar to Vb net xp_11

Certification preparation - Error Handling and Troubleshooting recap.pptx
Certification preparation - Error Handling and Troubleshooting recap.pptxCertification preparation - Error Handling and Troubleshooting recap.pptx
Certification preparation - Error Handling and Troubleshooting recap.pptxRohit Radhakrishnan
 
Aae oop xp_13
Aae oop xp_13Aae oop xp_13
Aae oop xp_13Niit Care
 
Chapter 08
Chapter 08Chapter 08
Chapter 08llmeade
 
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
 
Vb net xp_14
Vb net xp_14Vb net xp_14
Vb net xp_14Niit Care
 
Vb net xp_12
Vb net xp_12Vb net xp_12
Vb net xp_12Niit Care
 
Types of Exceptionsfsfsfsdfsdfdsfsfsdfsd
Types of ExceptionsfsfsfsdfsdfdsfsfsdfsdTypes of Exceptionsfsfsfsdfsdfdsfsfsdfsd
Types of Exceptionsfsfsfsdfsdfdsfsfsdfsdssuserce9e9d
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.netsuraj pandey
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeansHuu Bang Le Phan
 
Exception handling
Exception handlingException handling
Exception handlingRaja Sekhar
 
JP ASSIGNMENT SERIES PPT.ppt
JP ASSIGNMENT SERIES PPT.pptJP ASSIGNMENT SERIES PPT.ppt
JP ASSIGNMENT SERIES PPT.pptJAYAPRIYAR7
 
Lecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxLecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxVishuSaini22
 
Exception handling
Exception handlingException handling
Exception handlingIblesoft
 

Similar to Vb net xp_11 (20)

Certification preparation - Error Handling and Troubleshooting recap.pptx
Certification preparation - Error Handling and Troubleshooting recap.pptxCertification preparation - Error Handling and Troubleshooting recap.pptx
Certification preparation - Error Handling and Troubleshooting recap.pptx
 
Aae oop xp_13
Aae oop xp_13Aae oop xp_13
Aae oop xp_13
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
Lecture 20-21
Lecture 20-21Lecture 20-21
Lecture 20-21
 
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
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Vb net xp_14
Vb net xp_14Vb net xp_14
Vb net xp_14
 
Vb net xp_12
Vb net xp_12Vb net xp_12
Vb net xp_12
 
Types of Exceptionsfsfsfsdfsdfdsfsfsdfsd
Types of ExceptionsfsfsfsdfsdfdsfsfsdfsdTypes of Exceptionsfsfsfsdfsdfdsfsfsdfsd
Types of Exceptionsfsfsfsdfsdfdsfsfsdfsd
 
Savitch ch 16
Savitch ch 16Savitch ch 16
Savitch ch 16
 
Lecture 22 - Error Handling
Lecture 22 - Error HandlingLecture 22 - Error Handling
Lecture 22 - Error Handling
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.net
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeans
 
Exception handling
Exception handlingException handling
Exception handling
 
JP ASSIGNMENT SERIES PPT.ppt
JP ASSIGNMENT SERIES PPT.pptJP ASSIGNMENT SERIES PPT.ppt
JP ASSIGNMENT SERIES PPT.ppt
 
Savitch Ch 16
Savitch Ch 16Savitch Ch 16
Savitch Ch 16
 
6-Error Handling.pptx
6-Error Handling.pptx6-Error Handling.pptx
6-Error Handling.pptx
 
Lecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxLecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptx
 
Exception handling
Exception handlingException handling
Exception handling
 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Recently uploaded

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

Vb net xp_11

  • 1. Exception Handling and Debugging Objectives In this lesson, you will learn to: Identify the mechanism to handle run time errors Differentiate between structured and unstructured exception handling Handle exceptions Debug an application ©NIIT Exception Handling and Debugging/Lesson 11/Slide 1 of 30
  • 2. Exception Handling and Debugging Problem Statement 11.D.1 While executing the application for adding order details, if the server returns an error or there is insufficient memory to execute the application, an appropriate message should be displayed and the application should not terminate abruptly. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 2 of 30
  • 3. Exception Handling and Debugging Task List Identify the mechanism to handle errors. Write the code to handle errors. Execute the application to verify the results of exception handling. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 3 of 30
  • 4. Exception Handling and Debugging Task 1: Identify the mechanism to handle errors. An exception is termed as an abnormal condition encountered by an application during execution. Exception handling Is the process of providing an alternate path to be executed when the application is unable to execute in the desired way. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 4 of 30
  • 5. Exception Handling and Debugging Task 1: Identify the mechanism to handle errors. (Contd.) Structured exception handling All the exceptions are derived from the System.Exception class. System.Exception System.ApplicationException System.Windows.Forms.AxHost.InvalidActiveXStateException System.Runtime.Remoting.MetadataServices.SUDSParserException System.IO.IsolatedStorage.IsolatedStorageException System.Runtime.Remoting.MetadataServices.SUDSGeneratorException System.SystemException ©NIIT Exception Handling and Debugging/Lesson 11/Slide 5 of 30
  • 6. Exception Handling and Debugging Task 1: Identify the mechanism to handle errors. (Contd.) Structured exception handling (Contd.) Divides an application into blocks of code that have the probability of raising an error. Uses the Try…Catch…Finally statement. Errors are filtered in the Catch block. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 6 of 30
  • 7. Exception Handling and Debugging Just a Minute… In the Try…Catch…Finally statement, when is the code given in each of the blocks executed? ©NIIT Exception Handling and Debugging/Lesson 11/Slide 7 of 30
  • 8. Exception Handling and Debugging Task 1: Identify the mechanism to handle errors. (Contd.) User-defined exceptions Can be created by deriving a class from the ApplicationException class. Unstructured exception handling Is done by placing an On Error statement in a block of code. Uses the On Error GoTo statement to pass the control to a specific error handler when an error occurs. Uses the On Error Resume Next statement to pass control to the next executable statement when an error occurs. Uses the On Error GoTo 0 to disable an error handler. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 8 of 30
  • 9. Exception Handling and Debugging Task 1: Identify the mechanism to handle errors. (Contd.) Result: Since unstructured exception handling code is difficult to maintain, you will use structured exception handling to trap and handle errors for the given problem statement. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 9 of 30
  • 10. Exception Handling and Debugging Just a Minute… What is the difference between the On Error GoTo 0, On Error Resume Next, and On Error GoTo ErrorHandler statements and when is each of them used? ©NIIT Exception Handling and Debugging/Lesson 11/Slide 10 of 30
  • 11. Exception Handling and Debugging Task 2: Write the code to handle errors. Task 3: Execute the application to verify the results of exception handling. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 11 of 30
  • 12. Exception Handling and Debugging Problem Statement 11.P.1 A weekly order details report and a weekly query handling report have been created. Based on the user’s choice, the corresponding report should be displayed. If the report to be opened gives a loading error, an appropriate message should be displayed and the application should not end abruptly. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 12 of 30
  • 13. Exception Handling and Debugging Problem Statement 11.D.2 An application has been created to display the product ID for a product that costs more than $3000. A Windows Form has been designed with a ListBox control and a Button control. A data adapter has been created and the Base_Cost and ProdID columns of the table Product have been retrieved. A dataset has been generated for the data adapter. The code has been written for the Load event of the form to display the ProductID for the products with cost more than $3000 in the list box. However, the application does not give the expected output. The list box displays one product ID multiple times. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 13 of 30
  • 14. Exception Handling and Debugging Task List Identify the mechanism to trap the error. Identify the starting point to search for errors. Implement error trapping. Run the application and trace the error. Rectify the code. Verify the output of the code. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 14 of 30
  • 15. Exception Handling and Debugging Task 1: Identify the mechanism to trap the error. Tracing and rectifying an error is termed as debugging. In order to assist you in debugging logical and run-time errors, Visual Basic .NET provides extensive debugging tools. You can access these tools by using: Debug toolbar Debug menu ©NIIT Exception Handling and Debugging/Lesson 11/Slide 15 of 30
  • 16. Exception Handling and Debugging Task 1: Identify the mechanism to trap the error. (Contd.) In an application, by using the debugging tools, you can: Start execution Break execution Stop execution Result: You will use the debugging tools provided by Visual Studio .NET to trap and rectify the error. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 16 of 30
  • 17. Exception Handling and Debugging Task 2:Identify the starting point to search for errors. Result: Since the list box contains a product ID, it indicates that there is no error in the database connection. The error trap should be set starting from the line containing OleDbDAProduct.Fill(DsProduct1)command as the error occurs after the connection is opened. Task 3: Implement error trapping. Task 4: Run the application and trace the error. Two options in the Debug menu to start an application: The Start option The Start Without Debugging option ©NIIT Exception Handling and Debugging/Lesson 11/Slide 17 of 30
  • 18. Exception Handling and Debugging Task 4: Run the application and trace the error. (Contd.) You may select the Debug menu option and select any of the following, to instruct Visual Basic .NET regarding the execution of the code. Step Into Step Over Step Out Task 5: Rectify the code. Task 6: Verify the output of the code. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 18 of 30
  • 19. Exception Handling and Debugging Problem Statement 11.D.3 An application has been developed to connect to the database and retrieve customer details from the database. The code has been added in the Load event of the form, which will display customer details. However, the application generates an error, as it is not able to connect to the database. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 19 of 30
  • 20. Exception Handling and Debugging Task List Identify the mechanism to debug the code. Implement debugging. Rectify the code. Verify the output of the code. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 20 of 30
  • 21. Exception Handling and Debugging Task 1: Identify the mechanism to debug the code. Visual Basic provides you with some tools to debug your application during the break mode. Two of the debugging tools are listed below: The Locals window The Immediate window Result: As per the problem statement, the connection with the database server has failed. The connection to the database is being made with the help of variables that form part of the connection string. The connection to the database can fail if the values in the variables are not correct. To solve this problem, you need to use the Immediate window to see the value that the user enters and is stored in the variable db. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 21 of 30
  • 22. Exception Handling and Debugging Task 2: Implement debugging. Task 3: Rectify the code. Task 4: Verify the output of the code. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 22 of 30
  • 23. Exception Handling and Debugging Problem Statement 11.D.4 An application has been developed which displays the corresponding base cost and the product name of the product ID selected by the user from a list box. The general level declarations have been made and the code has been added. However, the application displays the product name and the base cost of the product ID P014 regardless of the ID selected by the user. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 23 of 30
  • 24. Exception Handling and Debugging Task List Identify the mechanism to debug the code. Implement debugging. Rectify the code. Verify the output of the code. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 24 of 30
  • 25. Exception Handling and Debugging Task 1: Identify the mechanism to debug the code. The following windows are used for debugging an application: Watch window Call Stack window The Output window ©NIIT Exception Handling and Debugging/Lesson 11/Slide 25 of 30
  • 26. Exception Handling and Debugging Task 1: Identify the mechanism to debug the code. (Contd.) Result: Since the variable prodid stores the selected item, its value has to be traced. Therefore, you will use the Watch window to trace the behavior of prodid. Task 2: Implement debugging. Task 3: Rectify the code. Task 4: Verify the output of the code. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 26 of 30
  • 27. Exception Handling and Debugging Summary In this lesson, you learned that: The types of errors that can occur in an application are syntax errors, run-time errors, and logical errors. An exception is an abnormal or condition that an application encounters during execution. Exception handling is the process of providing an alternate path to be executed when the application is not able to execute in the desired way. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 27 of 30
  • 28. Exception Handling and Debugging Summary (Contd.) Visual Basic .NET provides two methods to handle exceptions: Structured exception handling Unstructured exception handling In order to assist you in debugging logical and runtime errors, Visual Basic .NET provides extensive debugging tools. You can use the Visual Basic .NET Debug toolbar to access these tools. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 28 of 30
  • 29. Exception Handling and Debugging Summary (Contd.) By using the debugging tools, you can perform the following actions: Start execution Break execution ® Whilein break mode, the following windows can be used to trace and debug an application: ® Call Stack window ® Watch window ® Locals window ® Immediate window ©NIIT Exception Handling and Debugging/Lesson 11/Slide 29 of 30
  • 30. Exception Handling and Debugging Summary (Contd.) ® Output window Step through execution Stop execution ©NIIT Exception Handling and Debugging/Lesson 11/Slide 30 of 30