Programs would be less clear if you had to account for ____ exceptions in every method declaration

Skip to main content

  1. Possibly. Students have the responsibility of protecting their work from being used dishonestly. If another student makes use of your work even without your knowledge, you may still bear some responsibility for inadvertently helping another student to cheat. Your responsibility or exoneration would depend on how negligent you were about protecting your work. Certainly, if a student goes to great lengths to steal your work despite all reasonable precautions taken by you, you would not be found responsible for aiding a dishonest act. However, you should always keep your work to yourself as much as possible. Lending a friend a paper so that he can use it as a guide to writing his own, for instance, may implicate you in academic dishonesty if your friend uses your ideas, phrases, or passages in his paper, even if you never encouraged him to do so. It is never wise to share your work with others when collaboration is not allowed, and it is a violation of the Academic Honesty Policy to share completed assignments in a form that can be copied.
  1. Yes. Improper storage of prohibited notes, course materials, and study aids during an exam such that they are accessible or possible to view is a violation of the Academic Honesty Policy. Always make sure that any notes or study aids that you bring to an exam are safely stowed away in closed bags kept well out of view.
  1. Yes. You are responsible for correctly citing all ideas, phrases, and passages taken from other authors wherever they occur in your work, even in drafts of your papers. Failure to do so is plagiarism, a violation of the Academic Honesty Policy.
  1. Yes, in almost all instances. Once a charge of academic dishonesty has been brought, you must remain enrolled in the class unless the case is resolved in one of the following two ways:
    1. If you have signed an Instructor Resolution Warning Letter offered by your instructor, you may drop or withdraw from the course once the Warning Letter has been approved by the Board on Academic Honesty.
    2. If you are exonerated by the Board after a hearing, then you may drop or withdraw from the course. If you withdraw before your case is resolved or after you are found responsible under either the Instructor Resolution with Penalty process or Board Resolution process, you will be reinstated in the class.

No matter how difficult it is to stay in a course in which the professor has accused you of dishonesty, you must continue to attend class and fulfill all class obligations.

  1. Yes. You are responsible for correctly citing all ideas, phrases, and passages taken from other authors wherever they occur in your work, even in drafts of your papers. Failure to do so is plagiarism, a violation of the Academic Honesty Policy.
  1. Yes. It is a good idea to have others proofread your work to identify mistakes in spelling, punctuation, syntax and style, unless such proofreading is expressly prohibited. But you are being dishonest for claiming authorship of any content added by your friend. Your instructor would have every right to turn you over to the board if she suspects that you received unauthorized aid in fulfilling the assignment.
  1. Yes. Sharing permission codes with other students is the same as forging signatures or falsifying information on official academic documents such as drop/add forms, petitions, letters of permission, or any other official University document and is a violation of the Academic Honesty Policy.
  1. No. This is called “duplicate submission.” Students are expected to produce original work for all of their classes. Turning in an essay written for a different class is dishonest not only because you are misrepresenting it as work done for this class, but also because you have received a grade and critical input from your former instructor, thus giving you an unfair advantage over your classmates. Many times, however, you can use a former assignment as the basis for a new one. Confer with your instructor, show her the paper and discuss how you might develop the work in a way that can satisfy class requirements. It is ultimately your instructor’s decision whether it is appropriate to use work done in a different class for her course.
  1. Yes. In classes where collaboration on graded assignments is allowed, you must still do your own work. Always make sure you understand the extent of collaboration your instructor allows. If you are not sure, ask your instructor for clarification. Most instructors do not allow students to turn in identical work or assignments that contain identical work.
  1. No. No faculty member can punish you for alleged dishonesty without following the procedures outlined in the Academic Honesty Policy. The instructor can follow the Instructor Resolution with Penalty process by presenting you with the evidence of dishonesty, suggesting a penalty, referring you to the Academic Honesty Policy, and allowing you up to 48 hours to accept the penalty. Or he can turn the case over to the board for a hearing in a Board Resolution. He cannot punish you on his own. In a similar vein, no faculty member can “give you a break” and overlook an instance of academic dishonesty, as all University faculty and staff are obligated to report cases of suspected dishonesty to the board.
  1. No. This is called “facilitating academic dishonesty” and includes aiding another person in an act that violates the standards of academic honesty; allowing other students to look at one's own work during an exam or in an assignment where collaboration is not allowed; providing information, material, or assistance to another person in violation of course, departmental, or College academic honesty policies; and providing false information in connection with any academic honesty inquiry.
  1. No. Using automatic translation programs is the same as getting a friend to do your work for you and is dishonest.

Let’s now consider a problem where it is less clear whether an exception can be successfully fixed “on the fly.” Suppose you have a program that contains an array of Strings, which is initially created with just two elements.


If an attempt is made to add more than two elements to the array, an ArrayIndexOutOfBoundsException will be raised. This exception can be handled by extending the size of the array and inserting the element. Then the program’s normal execution can be resumed.

To begin creating such a program, let’s first design a method that will insert a string into the array. Suppose that this is intended to be a private method that will only be used within the program. Also, let’s suppose that the program maintains a variable, count, that tracks how many values have been stored in the array. Therefore, it will not be necessary to pass the array as a parameter. So, we are creating a void method with one parameter, the String to be inserted:


The comment notes where an exception might be thrown.

Can we handle this exception? When this exception is raised, we could create a new array with one more element than the current array. We could copy the old array into the new array and then insert the String in the new location. Finally, we could set the variable list, the array reference, so that it points to the new array. Thus, we could use the following try/catch block to handle this exception:


The effect of the catch clause is to create a new array, still referred to as list, but that contains one more element than the original array.

Note the use of the finally clause here. For this problem it’s important that we increment count in the finally clause. This is the only way to guarantee that count is incremented exactly once whenever an element is assigned to the array. 

The design of the FixArrayBound class is shown in Figure 10.17. It provides a simple GUI interface that enables you to test the insertString() method. This program has a standard Swing interface, using a JFrame as the top-level window. The program’s components are contained within a JPanel that’s added to the JFrame in the main() method. 

Each time the user types a string into the text field, the actionPerformed() method calls the insertString() method to add the string to the array. On each user action, the JPanel is repainted. The paintComponent() method simply clears the panel and then displays the array’s elements (Fig. 10.18).


The complete implementation of FixArrayBound is given in Figure 10–19. This example illustrates how an exception can be handled successfully and the program’s normal flow of control resumed. However, the question is whether such an exception should be handled this way.

Unfortunately, this is not a well-designed program. The array’s initial size is much too small for the program’s intended use. Therefore, the fact that these exceptions arise at all is the result of poor design. In general, exceptions should not be used as a remedy for poor design.


For a program that uses an array, the size of the array should be chosen so that it can store all the objects required by the program. If the program is some kind of failsafe program, which cannot afford to crash, then something like the previous approach might be justified, provided this type of exception occurs very rarely. Even in that case it would be better to generate a message that alerts the program’s user that this condition has occurred. The alert will indicate a need to modify the program’s memory requirements and restart the program.


Figure 10.18: The strings displayed are stored in an array that is extended each time a new string is entered.



If it is not known in advance how many objects will be stored in an array, a better design would be to make use of the java.util.Vector class (see “From the Java Library” in Chapter 9). Vectors are designed to grow as new objects are inserted. In some ways the exception-handling code in our example mimics the behavior of a vector. However, the Vector class makes use of efficient algorithms for extending its size. By contrast, exception-handling code is very inefficient. Because exceptions force the system into an abnormal mode of execution, it takes considerably longer to handle an exception than it would to use a Vector for this type of application.


SELF-STUDY EXERCISE 

EXERCISE 10.13 For each of the following exceptions, determine whether it can be handled in such a way that the program can be resumed or whether the program should be terminated: 

a. A computer game program detects a problem with one of its GUI elements and throws a NullPointerException. 

b. A factory assembly-line control program determines that an important control value has become negative and generates an ArithmeticException. 

c. A company’s Web-based order form detects that its user has entered an invalid String and throws a SecurityException.

Neuester Beitrag

Stichworte