您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Content Index

Content Page # 32

Exceptions and errors

The word ‘exception’ has a similar meaning to the word ‘error’, but ‘error’ is very vague in normal usage. It can mean a specific logical error in a line of program (like adding 2 when you should have added 3), or an incorrect operation on the part of the user (like opening a non-existent file). The first of these is simply a mistake on the part of the programmer, and no particular mechanisms exist to detect such mistakes. Finding errors like this is part of the normal process of testing and debugging. The second is an adverse input to the program, which must be detected and corrected by the program when it is running.

In Java, the words exception and error have reasonably well-defined meanings.

In Java, an exception is anything that would cause a program to deviate from its ‘normal’ course of operation. An exception may result from incorrect operation by the user, or failure of any part of the computer system on which the program is running. An exception may also arise because the programmer did not anticipate user inputs that are impossible to process (like asking a calculator to divide something by zero). In Java, some programming errors are also classified as exceptions, as will be discussed later.

In Java an error usually means a system error . That is, a serious problem resulting from something beyond the control of the programmer or the user.

Proper handling of exceptions is a mark of professionalism. In practice it is very difficult to write a program that responds correctly in response to every conceivable exception, and very expensive. However, if the software is controlling a safety-critical system (e.g., air traffic control) then the developers may aim for absolute reliability. In the ordinary commercial market, however, the programmers must aim for a good compromise between cost of development and quality of the final product.

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg