/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.except;

import java.io.PrintStream;
import java.io.PrintWriter;

/**
 * The root exception of all runtime exceptions thrown by the Venice core code.  It is capable of
 * "wrapping" another exception within it.
 *
 * @author Eric J. Bowersox &lt;erbo@silcom.com&gt;
 * @version X
 */
public class VeniceRuntimeException extends RuntimeException implements SupplyFaultCode
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private Throwable inner = null;           // internal "root cause" exception

  /*--------------------------------------------------------------------------------
   * Constructors
   *--------------------------------------------------------------------------------
   */

  /**
   * Constructs a new <CODE>VeniceRuntimeException</CODE>.
   */
  public VeniceRuntimeException()
  {
    super();

  } // end constructor

  /**
   * Constructs a new <CODE>VeniceRuntimeException</CODE> with a text message.
   *
   * @param msg The message to set in this exception.
   */
  public VeniceRuntimeException(String msg)
  {
    super(msg);

  } // end constructor

  /**
   * Constructs a new <CODE>VeniceRuntimeException</CODE> wrapping another exception.
   *
   * @param inner The exception wrapped by this one.
   */
  public VeniceRuntimeException(Throwable inner)
  {
    super(inner.getMessage());
    this.inner = inner;

  } // end constructor

  /**
   * Constructs a new <CODE>VeniceRuntimeException</CODE> wrapping another exception.
   *
   * @param msg The message to set in this exception.
   * @param inner The exception wrapped by this one.
   */
  public VeniceRuntimeException(String msg, Throwable inner)
  {
    super(msg);
    this.inner = inner;

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Overrides from class Throwable
   *--------------------------------------------------------------------------------
   */

  /**
   * Prints this exception and its backtrace to the standard error stream.  Also prints the backtrace
   * of any "wrapped" exception.
   *
   * @see java.lang.System#err
   */
  public void printStackTrace()
  {
    this.printStackTrace(System.err);

  } // end printStackTrace

  /**
   * Prints this exception and its backtrace to the specified <CODE>PrintStream</CODE>.  Also prints the
   * backtrace of any "wrapped" exception.
   *
   * @param s <CODE>PrintStream</CODE> to use for output.
   */
  public void printStackTrace(PrintStream s)
  {
    super.printStackTrace(s);
    VeniceException.printRootCause(s,inner);

  } // end printStackTrace

  /**
   * Prints this exception and its backtrace to the specified <CODE>PrintWriter</CODE>.  Also prints the
   * backtrace of any "wrapped" exception.
   *
   * @param s <CODE>PrintWriter</CODE> to use for output.
   */
  public void printStackTrace(PrintWriter s)
  {
    super.printStackTrace(s);
    VeniceException.printRootCause(s,inner);

  } // end printStackTrace

  /*--------------------------------------------------------------------------------
   * Implementations from interface SupplyFaultCode
   *--------------------------------------------------------------------------------
   */

  public int getFaultCode()
  {
    return 0;

  } // end getFaultCode

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  /**
   * Returns the exception wrapped by this exception, or <CODE>null</CODE> if there is none.
   *
   * @return See above.
   */
  public Throwable getException()
  {
    return inner;

  } // end getException

} // end class VeniceException
