Exercise 5 — Errors and exceptions Although many exceptions are the consequence of problems beyond the control of the programmer, some errors on the part of the programmer will be detectable in the form of exceptions. Which of the following errors on the part of a programmer do you think will (1) always given rise an exception? (2) possibly give rise to an exception or (3) not give rise to an exception? Assume that x, y and z are integer variables. | Statement written | Statement that should have been written | 1 | int x = y + 2; | int x = y + 4; | 2 | int x = y / 0; | int x = y / o; | 3 | int x = y/z; | int x = y/2; | 4 | int x = y[-1]; | int x = y[z - 1]; | 5 | int x = y[2] | int x = y[3]; |
Discussion/Suggested solution to Exercise 5 Back to content Back to top 
RITSEC - Global Campus Copyright ?1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |