/*
 * This file (PatientPrintException.java) is part of DebGen-ReportPrintLib  developed by ASTRID Research.
 * All rights reserved. Reproduction, modification, use or disclosure
 * to third parties without express authority is forbidden.
 *
 *  Copyright ASTRID Research, Hungary, 2010.
 *
 *  ASTRID Research
 *  Headquaters: Csapó utca 42. Debrecen H-4029 HUNGARY
 *  Phone: +36-52-533-173        Fax: +36-52-533-174
 *  Web: http://www.astrid.hu    E-mail: info@astrid.hu
 *
 * Project name: DEBGEN-Biobank-Project.
 * File last modified at 2010.01.06 20:12
 */

package hu.astrid.printxml.exception;

/**
 * Exception class, which can nest other exceptions
 * @author inagy
 */
public class PatientPrintException extends Exception {
    private static final long serialVersionUID = -2558150762601329391L;

    private String message;
    private Exception rootCause;

    /**
     * Creates a new PatientPrintException instance, and sets the nested exception
     * @param rootCause The nested exception
     */
    public PatientPrintException(Exception rootCause) {
        this.message = null;
        this.rootCause = rootCause;
    }

    /**
     * Creates a new PatientPrintException instance, and sets the message
     * @param message The message of the exception
     */
    public PatientPrintException(String message) {
        this.message = message;
        rootCause = null;

    }

    /**
     * Creates a new PatientPrintException instance, and sets the nested exception and the message
     * @param e The nested exception
     * @param message The message
     */
    public PatientPrintException(Exception e, String message) {
        this.message = message;
        rootCause = e;
        e.printStackTrace();
    }

    /**
     * Returns the nested exception
     * @return The original exception
     */
    public Exception getRootCause() {
        return rootCause;
    }

    @Override
    public void printStackTrace() {
        System.err.println("PatientPrintException throwed: " + getMessage() );
        if ( rootCause!= null ) {
            rootCause.printStackTrace();
        }
    }

    @Override
    public String getMessage() {
        if (message != null)
            return message;
        else
            return rootCause.getMessage();
    }
}
