package sac.util;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:
 * @author
 * @version 1.0
 */
import java.io.PrintStream;
import java.io.PrintWriter;

public class ChainException extends Exception{
  private Throwable parentError;

  public ChainException() {
    super();
  }

  public ChainException(Throwable _error) {
    this();
    setParentError(_error);
  }

  public ChainException(String msg) {
    super(msg);
  }

  public ChainException(String msg, Throwable _error) {
    this(msg);
    setParentError(_error);
  }

  public Throwable getParentError(){
    return parentError;
  }

  public void setParentError(Throwable _error){
    parentError = _error;
  }

  public void printStackTrace(){
    if ( parentError != null){
      parentError.printStackTrace();
    }
    super.printStackTrace();
  }

  public void printStackTrace(PrintStream stream){
    if ( parentError != null){
      parentError.printStackTrace(stream);
    }
    super.printStackTrace(stream);
  }

  public void printStackTrace(PrintWriter writer){
    if ( parentError != null){
      parentError.printStackTrace(writer);
    }
    super.printStackTrace(writer);
  }

  /**
   *
   */
  public static void main(String[] args) {
    try {
      throw new ChainException ("Teste ", new ChainException("Teste Pai"));
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }

  }

}