WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.

Slides:



Advertisements
Similar presentations
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Advertisements

WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Lecture 9. 2 Exception  An exception is a unusual, often unpredictable event, detectable by software or hardware, that requires special processing occurring.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Introduction to Computer Programming Error Handling.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010/2013.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010/2013.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
15 min WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010/2013.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
45 min WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010/2013.
WARNING 20 min These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING 40 min These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint.
15 min WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
WARNING 20 min These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint.
Presentation transcript:

WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint They may not show up well on other PowerPoint versions. You can download PowerPoint 2010 viewer from here.here These slides contain a lot of animations. For optimal results, watch in slideshow mode.

ARIANE 5 launch

Here’s an error message Navigation instructions?

Here’s an error message Navigation instructions? Your teammate’s code Your code

Your teammate’s code Putting up defences to protect our code. CS2103/T, Lecture 7, Part 3, [Oct 4, 2013]

Your code Your teammate’s code Putting up defences to protect our code.

Lecture 7: Putting up defences to protect our code.

GO!

… int size = Config.getSize(); if( 0 < size < 5) setSizeAsSmall(); else setSizeAsBig(); … if( sizeFound()) return readSize(); else return 0; … // size > 0

… int size = Config.getSize(); if( 0 < size < 5) setSizeAsSmall(); else setSizeAsBig(); … if( sizeFound()) return readSize(); else return 0; … assert (size > 0)

… int size = Config.getSize(); if( 0 < size < 5) setSizeAsSmall(); else setSizeAsBig(); … if( sizeFound()) return readSize(); else return 0; … assert (size > 0) Make your assumptions explicit. Get the runtime to confirm them.

GO!

What if age is invalid? void processAge(int age); //do stuff with age } bug? Handle or raise an Exception Verify using assertion e.g. assert(isValid(age)) void foo(String fileName); openFile(fileName); } User mishap

Handle or raise an Exception Developer User/environment bug? User mishap Verify using assertion e.g. assert(isValid(age))

Handle or raise an Exception

Handle or raise an Exceptions public void processInput(String[] input) { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exceptions public void processInput(String[] input) { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exceptions public void processInput(String[] input) { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exceptions public void processInput(String[] input) { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exceptions public void processInput(String[] input) { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exceptions public void processInput(String[] input) { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exceptions public void processInput(String[] input) { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exceptions public void processInput(String[] input) { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exceptions public void processInput(String[] input) { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exception public void processInput(String[] input) throws InvalidInputException { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); throw e; } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

Handle or raise an Exception public void processInput(String[] input) throws InvalidInputException { try { processArray(input); //do other things } catch (InvalidInputException e) { System.err.println(“Invalid input: " + e.getMessage()); throw e; } public void processArray(String[] array) throws InvalidInputException { if(array.size()==0){ throw new InvalidInputException(“empty array”); } //process array }

GO!

Your ToDo manager software tries to interact with Google calendar, but finds Google servers are down. This should be handled using, a)Assertions b)Exceptions c)Depends goog {a|b|c} e.g. goog b goog {a|b|c} e.g. goog b 77577

GO!

My computer crashes when I flush the toilet!

… int size = Config.getSize(); // size > 0 if( 0 < size < 5) log(LEVEL_INFO, “Setting size to small”); setSizeAsSmall(); else if( size > 5) setSizeAsBig(); else log(LEVEL_WARN, “size not recognized”); …

GO!

class Man{ Woman girlfriend; void setGirlFriend(Woman w){ girlfriend = w; } … class Woman{ Man boyfriend; void setBoyFriend(Man m){ boyfriend = m; } … Man harry, ron; Woman hermione; ron.setGirlFriend(hermoine); hermione.setBoyFriend(harry); … ron:Man hermione :Woman harry:Man girlfriend boyfriend

42 What do you do when it is green light?

Defensive driving can save your life Assume other drivers are idiots

Defensive driving can save your life Assume other drivers are idiots coding career coders

class Man{ Woman girlfriend; void setGirlFriend(Woman w){ if(girlfriend!=null) girlfriend.breakupWith(this); girlfriend = w; girlfriend.setBoyFriend(this); } …

Bertrand Meyer, Design by Contract and the Eiffel Language

GO!

AssertionsExceptionsLoggingDefensive

GO! AssertionsExceptionsLoggingDefensive *some* evidence of each, starting from V0.3