Your SlideShare is downloading. ×
0
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Vb net xp_11
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Vb net xp_11

602

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
602
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Exception Handling and DebuggingObjectivesIn this lesson, you will learn to:Identify the mechanism to handle run time errorsDifferentiate between structured and unstructured exception handlingHandle exceptionsDebug an application ©NIIT Exception Handling and Debugging/Lesson 11/Slide 1 of 30
  • 2. Exception Handling and DebuggingProblem Statement 11.D.1While executing the application for adding order details, if theserver returns an error or there is insufficient memory toexecute the application, an appropriate message should bedisplayed and the application should not terminate abruptly. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 2 of 30
  • 3. Exception Handling and DebuggingTask ListIdentify the mechanism to handle errors.Write the code to handle errors.Execute the application to verify the results of exceptionhandling. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 3 of 30
  • 4. Exception Handling and DebuggingTask 1: Identify the mechanism to handle errors.An exception is termed as an abnormal conditionencountered 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 DebuggingTask 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 DebuggingTask 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 DebuggingJust a Minute…In the Try…Catch…Finally statement, when is the codegiven in each of the blocks executed? ©NIIT Exception Handling and Debugging/Lesson 11/Slide 7 of 30
  • 8. Exception Handling and DebuggingTask 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 DebuggingTask 1: Identify the mechanism to handle errors.(Contd.)Result:Since unstructured exception handling code is difficult tomaintain, 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 DebuggingJust a Minute…What is the difference between the On Error GoTo 0, OnError Resume Next, and On Error GoTo ErrorHandlerstatements and when is each of them used? ©NIIT Exception Handling and Debugging/Lesson 11/Slide 10 of 30
  • 11. Exception Handling and DebuggingTask 2: Write the code to handle errors.Task 3: Execute the application to verify the resultsof exception handling. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 11 of 30
  • 12. Exception Handling and DebuggingProblem Statement 11.P.1A weekly order details report and a weekly query handlingreport have been created. Based on the user’s choice, thecorresponding report should be displayed. If the report to beopened gives a loading error, an appropriate message shouldbe displayed and the application should not end abruptly. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 12 of 30
  • 13. Exception Handling and DebuggingProblem Statement 11.D.2An application has been created to display the product ID for aproduct that costs more than $3000.A Windows Form has been designed with a ListBox controland a Button control.A data adapter has been created and the Base_Cost andProdID columns of the table Product have been retrieved. Adataset has been generated for the data adapter.The code has been written for the Load event of the form todisplay 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 DebuggingTask ListIdentify 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 DebuggingTask 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-timeerrors, Visual Basic .NET provides extensive debuggingtools. 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 DebuggingTask 1: Identify the mechanism to trap the error.(Contd.)In an application, by using the debugging tools, you can: Start execution Break execution Stop executionResult:You will use the debugging tools provided by VisualStudio .NET to trap and rectify the error. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 16 of 30
  • 17. Exception Handling and DebuggingTask 2:Identify the starting point to search for errors.Result:Since the list box contains a product ID, it indicates thatthere is no error in the database connection. The error trap should be set starting from the line containingOleDbDAProduct.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 DebuggingTask 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 OutTask 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 DebuggingProblem Statement 11.D.3An application has been developed to connect to the databaseand retrieve customer details from the database. The codehas been added in the Load event of the form, which willdisplay customer details.However, the application generates an error, as it is not ableto connect to the database. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 19 of 30
  • 20. Exception Handling and DebuggingTask ListIdentify 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 DebuggingTask 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 windowResult:As per the problem statement, the connection with thedatabase 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 Immediatewindow to see the value that the user enters and is stored inthe variable db. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 21 of 30
  • 22. Exception Handling and DebuggingTask 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 DebuggingProblem Statement 11.D.4An application has been developed which displays thecorresponding base cost and the product name of the productID selected by the user from a list box. The general leveldeclarations have been made and the code has been added.However, the application displays the product name and thebase cost of the product ID P014 regardless of the ID selectedby the user. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 23 of 30
  • 24. Exception Handling and DebuggingTask ListIdentify 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 DebuggingTask 1: Identify the mechanism to debug the code.The following windows are used for debugging anapplication: Watch window Call Stack window The Output window ©NIIT Exception Handling and Debugging/Lesson 11/Slide 25 of 30
  • 26. Exception Handling and DebuggingTask 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 Watchwindow 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 DebuggingSummaryIn this lesson, you learned that:The types of errors that can occur in an application aresyntax 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 DebuggingSummary (Contd.)Visual Basic .NET provides two methods to handleexceptions: Structured exception handling Unstructured exception handlingIn order to assist you in debugging logical and runtimeerrors, Visual Basic .NET provides extensive debuggingtools. You can use the Visual Basic .NET Debug toolbar toaccess these tools. ©NIIT Exception Handling and Debugging/Lesson 11/Slide 28 of 30
  • 29. Exception Handling and DebuggingSummary (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 DebuggingSummary (Contd.) ® Output window Step through execution Stop execution ©NIIT Exception Handling and Debugging/Lesson 11/Slide 30 of 30

×