package me.chyxion.tigon.exception;

import static org.slf4j.helpers.MessageFormatter.arrayFormat;

/**
 * Base Exception, Error Code 5000
 * @version 0.0.1
 * @since 0.0.1
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Oct 9, 2016 10:04:10 AM
 */
public class BaseException
    extends RuntimeException 
    implements ErrorCoded<Object> {
    private static final long serialVersionUID = 1L;
    public static final int CODE = 5000;
    protected Object code = CODE;
    
    public BaseException() {
    }

    public BaseException(Object code) {
        this.code = code;
    }
    
    public BaseException(Object code, Throwable e) {
        super(e);
        this.code = code;
    }

    public BaseException(Object code, String message, Object ... args) {
        this(message, args);
        this.code = code;
    }

    public BaseException(String message, Object ... args) {
        super(arrayFormat(message, args).getMessage(), 
            arrayFormat(null, args).getThrowable());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object getCode() {
        return code;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setCode(Object code) {
        this.code = code;
    }
}
