Java Reference
In-Depth Information
...
} catch (Exception e) {
...
} finally {// optional
... this code always executed even if
no exception occurs...
}
...
The code bracketed by the try-catch may throw the specific exceptions
NumberFormatException or IOException ,which are caught in the corre-
sponding catch sections. Any other type of exception thrown will be caught by
the third catch since it catches Exception ,which is the root of all exception
types. The finally keyword indicates that, regardless of whether an excep-
tion is thrown or not, the code block following finally is always executed.
Sometimes it is useful to use a try-finally block in which no exceptions
appear but one wants to be certain that the code in the finally block always
executes.
3.10 OOP in engineering and science
The same reasons that object-oriented programming benefits general pro-
gramming also apply to science and engineering applications. These benefits
include:
enhanced reusability of the code
modularity makes the code structure easier to understand and maintain
encapsulation helps to reduce the breaking of other codes when a change is made
enhancements of the code via inheritance (see next chapter) are made in a systematic
manner
OOP can also provide additional benefits to science and engineering. For exam-
ple, in the Web Course Chapter 3: Physics section we discuss how complicated
physical systems are reduced to essential parts and how these parts naturally fall
into object-type descriptions. Science, in general, usually seeks to segment com-
plex systems into simpler components. These components can easily correspond
to objects. Then these simpler objects can be grouped into composite objects that
correspond to the higher-order complex systems.
Forexample, one could easily imagine a set of classes providing the properties
and structures of a group of proteins. These could be useful to both chemists
and microbiologists, who would use them in their own programs for different
applications.
 
Search WWH ::




Custom Search