Modern JavaScript Develop And Design Instructor’s Notes Chapter 12 – Error Management Modern JavaScript Design And Develop Copyright © 2012 by Larry Ullman.

Slides:



Advertisements
Similar presentations
JUnit Tutorial Hong Qing Yu Nov JUnit Tutorial The testing problems The framework of JUnit A case study JUnit tool Practices.
Advertisements

Detecting Bugs Using Assertions Ben Scribner. Defining the Problem  Bugs exist  Unexpected errors happen Hardware failures Loss of data Data may exist.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Practice Session 5 Java: Packages Collection Classes Iterators Generics Design by Contract Test Driven Development JUnit.
Slides adapted from Alex Mariakakis, with material from Krysta Yousoufian, Mike Ernst, and Kellen Donohue Section 4: Graphs and Testing.
J-Unit Framework.
Exception Handling – illustrated by Java mMIC-SFT November 2003 Anders P. Ravn Aalborg University.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
Chapter 16: Exception Handling C++ Programming: From Problem Analysis to Program Design, Fifth Edition.
Objectives In this chapter you will: Learn what an exception is Learn how to handle exceptions within a program See how a try / catch block is used to.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
T ESTING WITH J UNIT IN E CLIPSE Farzana Rahman. I NTRODUCTION The class that you will want to test is created first so that Eclipse will be able to find.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 17 Exceptions and.
JUnit Syed Nabeel. Motivation Unit Testing Responsibility of  developer Rarely done properly Developers Excuse: “I am too much in a hurry”
25-Jun-15 JavaScript Language Fundamentals II. 2 Exception handling, I Exception handling in JavaScript is almost the same as in Java throw expression.
CS 635 Advanced Object-Oriented Design & Programming Spring Semester, 2006 Doc 2 Terms & Testing Jan 24, 2006 Copyright ©, All rights reserved SDSU.
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
Exception Error handling. Exception 4 n An unusual occurrence during program execution that requires immediate handling n Errors are the most common type.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 2- JavaScript in Action Modern JavaScript Design And Develop Copyright © 2012 by Larry.
Introduction to Computer Programming Error Handling.
Chapter 11 Exception Handling F Exceptions and Exception Types F Claiming Exceptions F Throwing Exceptions F Catching Exceptions F Rethrowing Exceptions.
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
Java Programming Exceptions Handling. Topics: Learn about exceptions Try code and catch Exceptions Use the Exception getMessage() method Throw and catch.
CIS 270—Application Development II Chapter 13—Exception Handling.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 10 – Working with Forms Modern JavaScript Design And Develop Copyright © 2012 by Larry.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 13 - Frameworks Modern JavaScript Design And Develop Copyright © 2012 by Larry Ullman.
1 Object Oriented Programming Testing with Unit Testing & the JUnit tool Basic Refactoring techniques.
Intoduction to Unit Testing Using JUnit to structure Unit Testing SE-2030 Dr. Rob Hasker 1 Based on material by Dr. Mark L. Hornick.
Exceptions Handling Exceptionally Sticky Problems.
COMP Exception Handling Yi Hong June 10, 2015.
JUnit test and Project 3 simulation. 2 JUnit The testing problems The framework of JUnit A case study Acknowledgement: using some materials from JUNIT.
Introduction to Exception Handling and Defensive Programming.
Chapter 14: Exception Handling. Objectives In this chapter, you will: – Learn what an exception is – Learn how to handle exceptions within a program –
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
JUnit A framework which provides hooks for easy testing of your Java code, as it's built Note: The examples from these slides can be found in ~kschmidt/public_html/CS265/Labs/Java/Junit.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Exceptions and Assertions Chapter 15 – CSCI 1302.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
CHAPTER 10 ERROR HANDLING & DEBUGGING JavaScript can be hard to learn. Everyone makes mistakes when writing it.
Unit Testing with FlexUnit
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
JUnit Testing Why we do this and how we can get better.
Exception. Agenda Exception. Handling Exceptions. The finally Clause.
JavaScript Syntax Fort Collins, CO Copyright © XTR Systems, LLC Introduction to JavaScript Syntax Instructor: Joseph DiVerdi, Ph.D., MBA.
Exception Handling. VB.NET has an inbuilt class that deals with errors. The Class is called Exception. When an exception error is found, an Exception.
Today protected access modifier Using the debugger in Eclipse JUnit testing TDD Winter 2016CMPE212 - Prof. McLeod1.
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
EXCEPTIONS. Catching exceptions Whenever a runtime error occurs, it create an exception object. The program stops running at this point and Python prints.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Object Oriented Testing (Unit Testing)
Handling Exceptionally Sticky Problems
JavaScript - Errors & Exceptions Handling
Modern JavaScript Develop And Design
Chapter 14: Exception Handling
Modern JavaScript Develop And Design
Test Driven Lasse Koskela Chapter 2: Beginning TDD
CMPE212 – Stuff… Assn 2 due this Friday. Winter 2018
Credit to Eclipse Documentation
Introduction to JUnit IT323 – Software Engineering II
Programming in C# CHAPTER - 7
Fall 2018 CISC124 2/1/2019 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
CMPE212 – Reminders Assignment 2 due this Friday.
Modern JavaScript Develop And Design
CMPE212 – Reminders Assignment 2 due this Friday.
Handling Exceptionally Sticky Problems
CS-1020 and Exception Handling
Debugging and Handling Exceptions
Presentation transcript:

Modern JavaScript Develop And Design Instructor’s Notes Chapter 12 – Error Management Modern JavaScript Design And Develop Copyright © 2012 by Larry Ullman

Objectives Perform exception handling using try…catch Add a finally clause to a try statement Throw exceptions Create and use assertions Implement unit testing

Catching Errors try { // Lots of code. } catch (error) { // Use error. } try { doThis(); doThat(); } catch (error) { // Use the error somehow. }

The Error Object try { // Lots of code. } catch (ex) { console.log(error.name + ': ' + error.message + '\n'); }

Finally… try { // Lots of code. } catch (ex) { // Use ex. } finally { // Wrap up. }

Throwing Exceptions throw something; throw 2; // Assumes 2 is meaningful in the catch. throw 'No such HTML element!'; throw new Error('No such HTML element!');

Throwing Exceptions function $(id) { 'use strict'; if (typeof id != 'undefined') { return document.getElementById(id); } else { throw Error('The function requires one argument.'); }

Using Assertions function assert(expression, message) { if (!expression) throw {name: 'Assertion Exception', message: message}; }

Unit Testing Define tests to confirm specific bits of code work as intended Tests should be atomic Add tests as the project evolves

Using jsUnity 1.Include the framework 2.Define tests 3.Run tests 4.Log results 5.Setup and teardown, as needed

Including the Framework

Defining Tests var myTests = function() { function testThis() { } };

Assertion Methods assertTrue() assertFalse() assertIdentical() assertNotIdentical() assertEqual() assertNotEqual() assertTypeOf() assertNotTypeOf() assertInstanceOf() assertNull() assertNotNull() assertUndefined() jsUnity.assertions.assertNotUndefined(myVar); jsUnity.assertions.assertTypeOf('number', radius); jsUnity.assertions.assertNotNaN(volume);

Running Tests var results = jsUnity.run(myTests); // results.total // results.passed // results.failed // results.duration

Logging Results jsUnity.log = function(message) { // Do something with message. };