package ModSQL;

/* $Id: SQLExceptionWithCause.java,v 1.1 2003/05/29 07:55:43 cvs Exp $
 *
 * Copyright (c) 2003 Chris Studholme <chris.studholme@utoronto.ca>
 *
 * May be copied or modified under the terms of the GNU General Public
 * License.  See COPYING for more information.
 */

/**
 * Updated version of SQLException implementing Java 1.4 cause objects.
 *
 * @author chris.studholme@utoronto.ca
 */
public class SQLExceptionWithCause extends java.sql.SQLException { 

  /** Cause of exception. */
  private Throwable cause;

  /**
   * Default constructor.
   */
  public SQLExceptionWithCause() {
    super();
  }

  /**
   * Exception with a specific reason.
   *
   * @param message reason exception was thrown
   */
  public SQLExceptionWithCause(String message) {
    super(message);
  }

  /**
   * Exception that was caused by some other exception.
   *
   * @param message reason exception was thrown
   * @param cause the cause of this exception
   */
  public SQLExceptionWithCause(String message, Throwable cause) {
    super(cause==null ? message : message+" (was "+cause.toString()+")");
  }

  /**
   * Exception that was caused by some other exception.
   *
   * @param cause the cause of this exception
   */
  public SQLExceptionWithCause(Throwable cause) {
    super(cause==null ? null : cause.toString());
  }

  /**
   * Returns the cause of this throwable or null if the cause is nonexistent 
   * or unknown. (The cause is the throwable that caused this throwable to
   * get thrown.)
   *
   * @return the cause of this throwable or null if the cause is unknown
   */
  public Throwable getCause() {
    return cause;
  }
  


};
