[ Pobierz całość w formacie PDF ]
.java doesn’t fail by throwing aRuntimeException inside the try block.[ Add Comment ]ModifyExercise 6 by adding a finally clause.Verify your finally clauseis executed, even if a NullPointerException is thrown.[ Add Comment ]Createan example where you use a flag to control whether cleanup code is called, asdescribed in the second paragraph after the heading “Constructors.”[ Add Comment ]ModifyStormyInning.java by adding an UmpireArgument exception type, andmethods that throw this exception.Test the modified hierarchy.[ Add Comment ]Removethe first catch clause in Human.java and verify that the code stillcompiles and runs properly.[ Add Comment ]Adda second level of exception loss to LostMessage.java so that theHoHumException is itself replaced by a third exception.[ Add Comment ]InChapter 5, find the two programs called Assert.java and modify these tothrow their own type of exception instead of printing to System.err.Thisexception should be an inner class that extends RuntimeException.[ Add Comment ]Addan appropriate set of exceptions to c08:GreenhouseControls.java.[ Add Comment ][51]The C programmer can look up the return value of printf( ) for anexample of this.[52]This is a significant improvement over C++ exception handling, whichdoesn’t catch violations of exception specifications until run time, whenit’s not very useful.[53]C++ exception handling does not have the finally clause because it relieson destructors to accomplish this sort of cleanup.[54]A destructor is a function that’s always called when an object becomesunused.You always know exactly where and when the destructor gets called.C++has automatic destructor calls, but Delphi’s Object Pascal versions 1 and2 do not (which changes the meaning and use of the concept of a destructor forthat language).[55]ISO C++ added similar constraints that require derived-method exceptions to bethe same as, or derived from, the exceptions thrown by the base-class method.This is one case in which C++ is actually able to check exception specificationsat compile-time.[56]In C++, a destructor would handle this for you.[ ][ ][ ][ ][ ]Last Update:05/21/2001
[ Pobierz całość w formacie PDF ]