Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Study guide: Exceptions to the programming rules, Part 2

Brush up on Java terms, learn tips and cautions, review homework assignments, and read Jeff's answers to student questions

  • Print
  • Feedback

Page 2 of 2

  • What is wrong with the article's SortIntegerArray1 source code?
  • Is the following code fragment legal?

    static void a () throws FileNotFoundException
    {
       try
       {
           throw new FileNotFoundException ();
       }
       catch (FileNotFoundException e)
       {
       }
    }
    


    Why or why not? Assume the code fragment is from a program that has an import java.io.FileNotFoundException; directive.

  • Can a try block appear alone in source code?
  • Why should you use multiple catch clauses instead of one all-encompassing catch clause?
  • Does Java allow any class's objects to be thrown?
  • Rewrite TranslatedExceptionDemo2 to eliminate the ee.initCause (e); method call, but produce the same output.
  • Write a program that demonstrates catching an exception object after performing cleanup tasks. Choose appropriate cleanup tasks for that program.


Answers to last month's homework

  • In last month's excdemo C++ source code and ExcDemo Java source code, why did I not combine, in the same try block, the code that pops integer values from the stack with the code that pushes integer values onto the stack?

    Answer: When an exception object is thrown from a try block, execution leaves that block and an exception handler executes. Once that exception handler completes, the try block's execution does not resume. Therefore, if I were to combine the "push" code with the "pop" code in the same try block, execution would leave the try block after the push-related exception. Because execution would not return to the try block, you would not have a chance to see the pop-related exception -- because the code that pops integers from the stack would never execute.



  • Print
  • Feedback

Resources