Download presentation
Presentation is loading. Please wait.
Published by遂 荣 Modified over 7 years ago
1
Exceptions throw new RuntimeException(“bad things happened”); The above line is the simplest possible way of throwing an exception. In Java, exceptions have a hierarchy. Every type of exception extends a base class called Exception. For this course we do not need you to understand (or for that matter memorize) the types of exceptions. 2
2
try and catch try { //some code that might throw an exception } catch (SomeSpecificExceptionType e) { // what you want to do in that case // usually after handling the exception you will either // a) e.printStackTrace(); // b) throw(e); See ExceptionHandler.java in JavaExperiments project in Dropbox.
3
Unit testing What to test first? Pick a function that is independent
Write tests for that. Watch tests fail. Write code for that until green bar (for that test). Write a bunch of test cases for this same function and get them to all pass. Pick a function that is either independent or dependent on the set of functions that you have tested. Repeat steps 3 – 7 until all functions are tested. In class – example of unit testing SetOfNames 3
4
toString, equals Your equals method should not call a toString() method. If both methods are basically doing the same thing, take that common piece of code and put it into its own private method. remember the M word???? Since you want to override these methods you do not have a choice on the method declaration public String toString() {} public boolean equals(Object obj) {}
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.