Error Handling.

Slides:



Advertisements
Similar presentations
Copyright 2008 Sun Microsystems, Inc Better Expressiveness for HTM using Split Hardware Transactions Yossi Lev Brown University & Sun Microsystems Laboratories.
Advertisements

Detecting Bugs Using Assertions Ben Scribner. Defining the Problem  Bugs exist  Unexpected errors happen Hardware failures Loss of data Data may exist.
Exceptions: when things go wrong. Various sources of error public static doSomething() { int i = 3.0; while(!done); { int i = false } ) Syntactic errors.
Yoshi
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Jerry Lebowitz. Topics  Provides a facility for a systematic object oriented approach to handling runtime errors ◦ Can also handle runtime errors.
Exceptions Briana B. Morrison CSE 1302C Spring 2010.
API Design CPSC 315 – Programming Studio Fall 2008 Follows Kernighan and Pike, The Practice of Programming and Joshua Bloch’s Library-Centric Software.
11-Jun-15 Exceptions. 2 Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a.
16-Jun-15 Exceptions. Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a null.
Exceptions. Errors and Exceptions An error is a bug in your program –dividing by zero –going outside the bounds of an array –trying to use a null reference.
CONTENTS:-  What is Event Log Service ?  Types of event logs and their purpose.  How and when the Event Log is useful?  What is Event Viewer?  Briefing.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
June 14, 2001Exception Handling in Java1 Richard S. Huntrods June 14, 2001 University of Calgary.
1 Defensive Programming and Debugging (Chapters 8 and 23 of Code Complete) Tori Bowman CSSE 375, Rose-Hulman September 21, 2007.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Exceptions1 Syntax, semantics, and pragmatics. Exception create If (some error){ throw new SomeException(”some message”); } Exceptions2.
Errors And How to Handle Them. GIGO There is a saying in computer science: “Garbage in, garbage out.” Is this true, or is it just an excuse for bad programming?
How to Design Error Steady Code Ivaylo Bratoev Telerik Corporation
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
Object Oriented Software Development 8. Exceptions, testing and debugging.
Oracle Data Integrator Procedures, Advanced Workflows.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 20 Slide 1 Critical systems development 3.
Ready Marjan Nikolovski Father, Dev, CEO/Emit Knowledge Down the rabbit hole Error handling examined try { } // // Blog: emitknowledge.com/research-labs.
Exceptions cs1043. Program Exceptions When a program detects an error, what should it do? – Nothing, simply allow the program to fail. – Implement a course.
Exception Handling Programmers must deal with errors and exceptional situations: User input errors Device errors Empty disk space, no memory Component.
QA and Testing. QA Activity Processes monitoring Standards compliance monitoring Software testing Infrastructure testing Documentation testing Usability.
Vinay Paul. CONTENTS:- What is Event Log Service ? Types of event logs and their purpose. How and when the Event Log is useful? What is Event Viewer?
Debugging Computer Networks Sep. 26, 2007 Seunghwan Hong.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
While You Were Sleeping… SAS Is Hard At Work Andrea Wainwright- Zimmerman.
Error Handling Tonga Institute of Higher Education.
Outsourcing, subcontracting and COTS Tor Stålhane.
CHAPTER 10 ERROR HANDLING & DEBUGGING JavaScript can be hard to learn. Everyone makes mistakes when writing it.
(c) University of Washington10-1 CSC 143 Java Errors and Exceptions Reading: Ch. 15.
IMS 3253: Validation and Errors 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Validation and Error Handling Validation.
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Google C++ Testing Framework Part 2: Assertion. Concepts A test case contains one or many tests. ◦ You should group your tests into test cases that reflect.
Exceptions in OO Programming Introduction Errors Exceptions in Java Handling exceptions The Try-Catch-Finally mechanism Example code Exception propagation.
Introduction to Exceptions in Java CS201, SW Development Methods.
Exception testing Aistis Karkauskas, IFM-2/2. Introduction  Exceptions – anomalous or exceptional events requiring special processing – often changing.
Eighth Lecture Exception Handling in Java
Exceptions In this lecture:
Defensive Programming
Lesson 04: Conditionals Topic: Introduction to Programming, Zybook Ch 3, P4E Ch 3. Slides on website.
The Software Development Cycle
The Pseudocode Programming Process
Exceptions 10-Nov-18.
Exceptions & Error Handling
CSC 143 Error Handling Kinds of errors: invalid input vs programming bugs How to handle: Bugs: use assert to trap during testing Bad data: should never.
Part B – Structured Exception Handling
Exceptions.
Programming in C# CHAPTER - 7
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
Bugs & Debugging - Testing
Problems Debugging is fine and dandy, but remember we divided problems into compile-time problems and runtime problems? Debugging only copes with the former.
Exceptions 25-Apr-19.
Exceptions 22-Apr-19.
Exceptions 10-May-19.
Computer Science 340 Software Design & Testing
Exceptions References: Jacquie Barker, Beginning Java Objects; Rick Mercer, Computing Fundamentals With Java; Wirfs-Brock et. al., Martin Fowler, OOPSLA.
Learning Intention I will learn about the standard algorithm for input validation.
Test-Driven Development
Exceptions 5-Jul-19.
IST256 : Applications Programming for Information Systems
The Software Development Cycle
Defensive Programming
Presentation transcript:

Error Handling

COSC 494: Human-Centric Software Engineering State of the practice in SE tools Demo tools in class State of the art in SE research Discuss research papers Adv topics in SE Code reviewing, continuous integration Program analysis, empirical methods Design, implement, and evaluate an SE tool Individual project

var contents = File.ReadAllText(”settings.txt"); What if file isn’t there? CRASH!

if(File. Exists(“settings. txt”)) { var contents = File if(File.Exists(“settings.txt”)) { var contents = File.ReadAllText(”settings.txt"); } What if file isn’t there? CRASH!

Does your program handle everything? File doesn’t exist File contents are not as expected Connection to database fails Users enter invalid input

Check for errors What assumptions are you making? Could a value be null? Are there error codes? Special cases? String.IndexOf() Returns -1 if doesn’t exist StringReader.ReadLine() Returns null if there are no more Enumerable.Filter() Returns [] if doesn’t exist String.Contains() Returns false if doesn’t exist String.Substring() Returns “” if doesn’t exist

How to handle errors? End the program Ostrich algorithm Notify the user with clear explanation Return the program to a valid state Retry Catch the exception

Retry Logic data = httpClient.Get(“https://fb.com/api/friends/”); attempts = 0; do { attempts++; data.status = httpClient.Get(“https://fb.com/api/friends/”); if(data == SUCCESS) { break; } sleep(delay); } while (tries < maxAttempts); HandleFailure(); https://alastaircrabtree.com/implementing-a-simple-retry-pattern-in-c/

Exception Handling try { // Code that might fail } catch { // Code to handle the failure finally { // Optional: clean up after the try and catch

Downsides of error handling Lots of added code Makes code complex and hard to read Hard to test Exceptions are fancy GOTOs Advice? Reduce the number of potential errors Recover when possible Provide helpful error messages Keep code clean Don’t be lazy

A bad error message

A bad error message

A good error message

Gracefully handle crashes when possible Provide helpful message to user Log the crash along with info to debug The error/exception Where it occurred Any info to help replicate Clean up Don’t leave files in corrupt state Close connections and deallocate memory