com.holub.tools
Class ThrowableContainer

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by com.holub.tools.ThrowableContainer
All Implemented Interfaces:
Serializable

public class ThrowableContainer
extends RuntimeException

A convenient container for realying a checked Exception from a method that can't declare a throws clause to a calling method that can. This doesn't happen very often, but occasionally you don't want to declare an interface method as throwing an exception that one of the methods called from the implementation actually throws. Use it like this:

        inteface X
        {       void interfaceMethod(); // throws nothing.
        }

        void interfaceMethod()
        {       try
                {
                        g();    // throws an IOException
                }
                catch( IOException e )
                {       throw new ThrowableContainer( e );
                }
        }

        void caller(X implementation) thows IOException
        {       try
                {       implementation.interfaceMethod();
                }
                catch( ThrowableContainer e )
                {       throw (IOException)(e.contents());
                }
        }
        

See Also:
Serialized Form
©2004 Allen I. Holub. All rights reserved.

This code may be used freely by yourself with the following restrictions:

  1. Your splash screen, about box, or equivalent, must include Allen Holub's name, copyright, and URL. For example:

    This program contains Allen Holub's SQL package.
    (c) 2005 Allen I. Holub. All Rights Reserved.
    http://www.holub.com


    If your program does not run interactively, then the foregoing notice must appear in your documentation.
  2. You may not redistribute (or mirror) the source code.
  3. You must report any bugs that you find to me. Use the form at http://www.holub.com/company/contact.html or send email.
  4. The software is supplied as is. Neither Allen Holub nor Holub Associates are responsible for any bugs (or any problems caused by bugs, including lost productivity or data) in any of this code.

Constructor Summary
ThrowableContainer(Throwable contents)
           
 
Method Summary
 Throwable contents()
           
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThrowableContainer

public ThrowableContainer(Throwable contents)
Method Detail

contents

public Throwable contents()