package com.jscape.util.event;

import com.jscape.util.Assert;

/**
 * @author Alex Usun
 */
public class HandleException
        extends RuntimeException {

    /**
     * Abstract event.
     */
    private final AbstractEvent source;

    /**
     * @param source source
     */
    public HandleException(AbstractEvent source) {
        this(null, null, source);
    }

    /**
     * @param message message
     * @param source  source
     */
    public HandleException(String message, AbstractEvent source) {
        this(message, null, source);
    }

    /**
     * @param cause  cause
     * @param source source
     */
    public HandleException(Throwable cause, AbstractEvent source) {
        this(cause == null ? null : cause.toString(), cause, source);
    }

    /**
     * @param message message
     * @param cause   cause
     * @param source  source
     */
    public HandleException(String message, Throwable cause, AbstractEvent source) {
        super(message, cause);

        Assert.notNull(source);
        this.source = source;
    }

    /**
     * @return AbstractEvent instance
     */
    public AbstractEvent getSource() {
        return this.source;
    }

}
