Sams Teach Yourself C++ in 21 Days
Bugs, Errors, Mistakes, and Code Rot ................................................................ It is rare for a real-worl ...
Handling Errors and Exceptions 717 20 Exceptional Circumstances ................................................................ ...
Listing 20.1 was actually designed to crash; however, if you had asked the user to enter two numbers, he could have encountered ...
Handling Errors and Exceptions 719 20 The Parts of Exception Handling .......................................................... ...
in the previous example, the exception is checked to see if it matches the indicated type. If not, the next catchstatement is ch ...
Handling Errors and Exceptions 721 20 6: int main() 7: { 8: int top = 90; 9: int bottom = 0; 10: 11: try 12: { 13: cout << ...
722 Day 20 tryBlocks A tryblock is a series of statements that begins with the keyword try; it is followed by an opening brace a ...
Handling Errors and Exceptions 723 20 With this statement,exceptionis thrown. This causes control to be passed to a handler. If ...
Unlike the prior listing, this listing takes more control of its exceptions. Although this isn’t the best use of exceptions, it ...
Handling Errors and Exceptions 725 20 18: // accessors 19: int GetitsSize() const { return itsSize; } 20: 21: // friend function ...
66: if (offSet >= 0 && offSet < GetitsSize()) 67: return pType[offSet]; 68: throw xBoundary(); 69: return pType[0] ...
Handling Errors and Exceptions 727 20 intArray[7] okay... intArray[8] okay... intArray[9] okay... intArray[10] okay... intArray[ ...
accessed. This causes the test on line 66 to fail, and operator[]raises an xBoundary exception on line 67. Program control switc ...
Handling Errors and Exceptions 729 20 If the exception reaches all the way to the beginning of the program (main()) and is still ...
25: class xBoundary {}; 26: class xTooBig {}; 27: class xTooSmall{}; 28: class xZero {}; 29: class xNegative {}; 30: private: 31 ...
Handling Errors and Exceptions 731 20 73: int main() 74: { 75: try 76: { 77: Array intArray(0); 78: for (int j = 0; j < 100; ...
Try this with a number of values for the size of the array. Then try putting in –5. You might have expected xNegativeto be calle ...
Handling Errors and Exceptions 733 20 21: // friend function 22: friend ostream& operator<< (ostream&, const Array ...
70: 71: return pType[0]; // appease MFC 72: } 73: 74: int main() 75: { 76: try 77: { 78: Array intArray(0); 79: for (int j = 0; ...
Handling Errors and Exceptions 735 20 The Arrayis created with size zero, but what’s this? The wrong exception appears to be cau ...
«
33
34
35
36
37
38
39
40
41
42
»
Free download pdf