package com.jscape.inet.terminal.events;

import com.jscape.inet.terminal.TerminalListener;

/**
 * Represents <code>Terminal</code> exception event. This event is generated
 * when any exception occured. Holds information about exception.
 */
public class ExceptionEvent
        implements TerminalEvent {

    private final Exception exception;

    //----------------------------------------------------------------------------

    /**
     * Creates <code>ExceptionEvent</code> object giving occured exception.
     *
     * @param ex exception.
     */
    public ExceptionEvent(Exception ex) {
        if (ex == null) {
            throw new NullPointerException("ExceptionEvent.constructor(): null passed");
        }

        this.exception = ex;
    }

    //----------------------------------------------------------------------------

    /**
     * Returns exception.
     *
     * @return exception.
     */
    public Exception getException() {
        return this.exception;
    }

    //----------------------------------------------------------------------------

    /**
     * Calls correct callback method of <code>TerminalListener</code> object.
     *
     * @param listener <code>TerminalListener</code> object.
     */
    public void accept(TerminalListener listener) {
        listener.onExceptionEvent(this);
    }

}