Presentation is loading. Please wait.

Presentation is loading. Please wait.

ERROR HANDLING AND DEBUGGING

Similar presentations


Presentation on theme: "ERROR HANDLING AND DEBUGGING"— Presentation transcript:

1 ERROR HANDLING AND DEBUGGING
9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 1

2 Objectives Write a program that uses structured exceptions.
Compare the exception hierarchy in Java with the exception hierarchy in .NET Use a Try...Catch...Finally construct. Throw exceptions Create custom exceptions Perform debugging techniques. Identify the principles of debugging Identify debugging strategies Set breakpoints and step through code Use the call stack to isolate a problem Compare the following types of testing: Desk checking, Unit testing, Integration testing, Code reviews. Compare and contrast black box, white box, and architectural tests Describe the purpose of unit testing Describe the purpose of integration testing Design tests 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 2

3 Exception Class Hierarchy (Java)
java.lang java.io Throwable Interface Serializable Exception Error RuntimeException 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 3

4 Exception Class Hierarchy .NET
System.Object System.Exception ISerializable System.ApplicationException System.SystemException 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 4

5 Try…Catch…Finally Try Catch Finally Code that might throw an exception
Code to handle the exception Finally Cleanup code to execute when exit is normal or because of exception 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 5

6 Standard Exception Handling Options
Log exception Ask for input Use default or alternate value Forward control somewhere else Convert the exception Ignore the exception Retry the action that caused the exception Take a recovery action Prepare to terminate 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 6

7 Dos and Don’ts Dos Don’t Handle exceptions if you can
Handle specific exceptions specifically Log exceptions Convert exceptions to a business context Don’t Ignore an exception Use blanket exception handling Convert a specific exception to a general exception Handle an exception you could avoid 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 7

8 Custom Exceptions (Java)
Define the exception class public class MyException extends Exception Declare the methods as “throws CustomerException” public void MyMethod () throws MyException Throw the exception Throw new MyException(“Problem”) 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 8

9 Custom Exceptions (VB.NET)
Define the exception class Public Class MyException Inherits Exception Throw the exception Throw new MyException(“Problem”) 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 9

10 Common Misconceptions about Testing
Developers should do no testing Developers should do all the testing You just need to do one thing to test You can fully test an application 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 10

11 Types of Testing Black box White box Architectural Testers and users
Developers Architectural Load test Performance test Security test Stress test Usability test 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 11

12 Improving testability
Modularize code Use encapsulation and interfaces Define services to relate to business behavior Define methods that capture State Flow 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 12

13 Moving to Integration Testing
Different coding styles might present an issue More use of abstraction and encapsulation Context and invocation order become important 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 13

14 Debugging Principles Know your system Repeatability
Understand the differences between the bug and your system Debugging requires testing 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 14

15 Debugging Strategies Reproduce the bug Test around the bug
Look for differences between systems where the bug occurs and where it doesn’t Narrow the scope Identify the “Point of Departure” Brainstorm with the group Look for similar problems in bug database Look for patterns over time Filter your system’s output Simulate system behavior Monitor the system 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 15

16 Debugging Techniques Breakpoints Stepping through code Watch window
Step into Step over Watch window Call stack 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 16

17 Summary In this unit, students learned:
How to perform structured error handling. How to create and throw exceptions. Methods for testing an application. Debugging techniques. 9/27/2019© 2006 ITT Educational Services Inc. Structured Programming: Unit 4 Slide 17


Download ppt "ERROR HANDLING AND DEBUGGING"

Similar presentations


Ads by Google