/*
 * ChainedException.java
 *
 * Created on 2 de Dezembro de 2006, 06:17
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package com.tecgraf.dao;

/**
 *
 * @author ismael
 */
public class ChainedException extends Exception {
  public static final long serialVersionUID = 01L;
  private Throwable cause = null;

  public ChainedException() {
    super();
  }

  public ChainedException( String message ) {
    super(message);
  }

  public ChainedException( Throwable cause ) {
    super(cause.getLocalizedMessage());
    this.cause = cause;
  }
  public ChainedException( String message, Throwable cause ) {
    super(message);
    this.cause = cause;
  }

  @Override
  public Throwable getCause() {
    return cause;
  }

  @Override
  public void printStackTrace() {
    super.printStackTrace();
    if( cause != null ) {
      System.err.println("Caused by:");
      cause.printStackTrace();
    }
  }

  @Override
  public void printStackTrace( java.io.PrintStream ps ) {
    super.printStackTrace(ps);
    if( cause != null ) {
      ps.println("Caused by:");
      cause.printStackTrace(ps);
    }
  }

  @Override
  public void printStackTrace( java.io.PrintWriter pw ) {
    super.printStackTrace(pw);
    if( cause != null ) {
      pw.println("Caused by:");
      cause.printStackTrace(pw);
    }
  }
}