slides-6

slides-6 - Data Structures - CSCI 102 Housekeeping (Lecture...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Data Structures - CSCI 102 Copyright © William C. Cheng Housekeeping (Lecture 7 - 2/1/2011) HW1 (Video Game Database) grading will start soon Lab #3 (Classes) due this week during your lab session A design doc is required before you can start your lab Typo fixed: there is no Extra Credit #2 HW2 (Extending the Video Game Database) available MSDNAA Questions? Done through the CS department (may be some time this week)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Data Structures - CSCI 102 Copyright © William C. Cheng CS102 C++ Exception Bill Cheng http://merlot.usc.edu/cs102-s11
Background image of page 2
Polymorphism (Ch 13) Virtual functions Abstract classes Interfaces C Structs (Ch 10) Topics to cover 3 Data Structures - CSCI 102 Copyright © William C. Cheng C++ Object-Oriented Programming C++ Classes (Ch 11) Constructors Destructors Member functions Exception Handling (Ch 15) Namespaces (Ch 8) Operator Overloading (Ch 14) Class Composition & Inheritance (Ch 12)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Return a special value from the function? When something goes wrong in one of your functions, how should you notify to the function caller? 4 Data Structures - CSCI 102 Copyright © William C. Cheng Exception Handling Return a bool indicating success/failure? Set a global variable? Print out an error message? Print an error and exit the program? Set a failure flag on somewhere (like " cin " does)? Handle the problem and just don’t tell the caller?
Background image of page 4
You should always notify the caller something happened. Silence is not an option. There’s something wrong with all those options. .. 5 Data Structures - CSCI 102 Copyright © William C. Cheng Exception Handling You can’t always return an error state (what if a function is supposed to return " bool "?) What if something goes wrong in a Constructor? What if the function where the error happens isn’t equipped to handle the error? All these strategies are passive . They require the caller to actively check if something went wrong. You don’t have a return value available
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Good sanity checks for development/testing The assert statement allows you to make sure certain conditions are true and immediately halt your program if they’re not 6 Data Structures - CSCI 102 Copyright © William C. Cheng The " assert " Statement Not ideal for an end product #include <cassert> int divide( int num, int denom) { assert(denom != 0 ); return (num/denom); }
Background image of page 6
interrupts the normal flow of execution Used when code has encountered a problem, but the current code can’t handle that problem itself 7 Data Structures - CSCI 102 Copyright © William C. Cheng The " throw " Statement #include <cassert> int divide( int num, int denom) { if(denom == 0 ) throw denom; return (num/denom); } Gives the caller the opportunity to catch and handle it If nothing deals with it, the program will terminate What can you give to the throw statement? Anything!
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

slides-6 - Data Structures - CSCI 102 Housekeeping (Lecture...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online