Download presentation
Presentation is loading. Please wait.
1
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 7 Semantics Ismael: “Surely all this is not without meaning.” Herman Melville, Moby Dick
2
Copyright © 2006 The McGraw-Hill Companies, Inc. Contents 7.1 Motivation 7.2 Expression Semantics 7.3 Program State 7.4 Assignment Semantics 7.5 Control Flow Semantics 7.6 Input/Output Semantics 7.7 Exception Handling Semantics
3
Copyright © 2006 The McGraw-Hill Companies, Inc. Purpose Simplify programming Make applications more robust. What does robust mean?
4
Copyright © 2006 The McGraw-Hill Companies, Inc. (* Pascal - what can go wrong *) reset(file, name); (* open *) sum := 0.0; count := 0; while (not eof(file)) do begin read(file, number); sum := sum + number; count := count + 1; end; ave := sum / count;
5
Copyright © 2006 The McGraw-Hill Companies, Inc. Exception Handling Figure 7.9
6
Copyright © 2006 The McGraw-Hill Companies, Inc. #include int main () { char A[10]; cin >> n; try { for (int i=0; i<n; i++){ if (i>9) throw "array index error"; A[i]=getchar(); } catch (char* s) { cout << "Exception: " << s << endl; } return 0; }
7
Copyright © 2006 The McGraw-Hill Companies, Inc. Java Exception Type Hierarchy Figure 7.10
8
Copyright © 2006 The McGraw-Hill Companies, Inc. Creating a New Exception Class
9
Copyright © 2006 The McGraw-Hill Companies, Inc. Missing Argument Exception
10
Copyright © 2006 The McGraw-Hill Companies, Inc. Invalid Input Exception Figure 7.12
11
Copyright © 2006 The McGraw-Hill Companies, Inc. StackUnderflowException Class Figure 7.13
12
Copyright © 2006 The McGraw-Hill Companies, Inc. Throwing an Exception Figure 7.13
13
Copyright © 2006 The McGraw-Hill Companies, Inc. AssertException Class
14
Copyright © 2006 The McGraw-Hill Companies, Inc. Assert Class Figure 7.15
15
Copyright © 2006 The McGraw-Hill Companies, Inc. Using Asserts
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.