Java Reference
In-Depth Information
Include as much contextual information as possible (or practical) in the
error. This likely means that the code that detected the error must provide
this information.
Serious processing errors, or unmanaged errors, should be detected as
quickly as possible. In general, these types of errors should not allow pro-
cessing to continue.
Errors that cause abnormal termination should be logged to a file with com-
plete contextual information for convenient postmortem analysis.
COBOL is very good at managing simple error conditions. For example, most
COBOL programs validate the end user's input and report back any invalid input
to the end user. However, processing-type errors (file I/O errors, for example) can
be much more cumbersome. If you have been involved with any significant
COBOL project, you know already how difficult good error handling can be in
some cases. Let us explore the following example.
Suppose your system includes a currency rate calculation subroutine, and your
program uses that subroutine to perform currency rate conversions. What should
happen if you call the subroutine and that subroutine cannot read the record in the
database required for proper currency rate conversion? Clearly, the answer depends
on several factors, including whether your application is a batch or an interactive
one, and whether or not your application can continue without the rate.
It is a complex task to design and document a currency conversion subroutine
interface that supports each of these technical scenarios in addition to the business
interface requirements. The technical interface requirements (such as batch versus
online mode, calling program error processing capabilities, potential error condi-
tions of the subroutine, and error details in message form) will likely overwhelm, or
at least confuse, the business application interface requirements.
Java has the advantage of being designed more than 30 years after COBOL,
and so its architects have come up with a built-in solution for this type of require-
ment. This solution is, naturally enough, based on the use of objects. Java defines
a special object type called Exception . Classes can describe which exception objects
they will create, and which ones they can handle. Moreover, the compiler checks
class definitions to make sure that your classes contain appropriate logic for any
declared exceptions.
One important design objective of Java exceptions is that standard or business
logic should be separated from exception-processing logic as much as possible. At
the same time, exceptions, when they do happen, should be dealt with as soon as
possible and by the class that is closest to the problem.
Search WWH ::




Custom Search