package com.rollbar.payload.data.body;

import com.google.gson.annotations.SerializedName;
import com.rollbar.payload.utilities.ArgumentNullException;
import com.rollbar.payload.utilities.Validate;

public class ExceptionInfo {
    public static ExceptionInfo fromThrowable(Throwable error) throws ArgumentNullException {
        Validate.isNotNull(error, "error");
        String className = error.getClass().getSimpleName();
        String message = error.getMessage();
        return new ExceptionInfo(className, message, null);
    }

    @SerializedName("class")
    private final String className;
    private final String message;
    private final String description;


    public ExceptionInfo(String className) throws ArgumentNullException {
        this(className, null, null);
    }

    public ExceptionInfo(String className, String message, String description) throws ArgumentNullException {
        Validate.isNotNullOrWhitespace(className, "className");
        this.className = className;
        this.message = message;
        this.description = description;
    }

    public String className() {
        return this.className;
    }

    public ExceptionInfo className(String className) throws ArgumentNullException {
        return new ExceptionInfo(className, message, description);
    }

    public String message() {
        return this.message;
    }

    public ExceptionInfo message(String message) {
        try {
            return new ExceptionInfo(className, message, description);
        } catch (ArgumentNullException e) {
            throw new IllegalStateException("className shouldn't be null");
        }
    }

    public String description() {
        return this.description;
    }

    public ExceptionInfo description(String description) {
        try {
            return new ExceptionInfo(className, message, description);
        } catch (ArgumentNullException e) {
            throw new IllegalStateException("className shouldn't be null");
        }
    }
}

package com.rollbar.payload.data.body;

import com.google.gson.annotations.SerializedName;
import com.rollbar.payload.utilities.ArgumentNullException;
import com.rollbar.payload.utilities.Validate;

/**
 * Represents *non-stacktrace* information about an exception, like class, description, and message.
 */
public class ExceptionInfo {
    /**
     * Create an exception info from a throwable.
     * @param error the throwable
     * @return an exception info with information gathered from the error
     * @throws ArgumentNullException if the error is null
     */
    public static ExceptionInfo fromThrowable(Throwable error) throws ArgumentNullException {
        Validate.isNotNull(error, "error");
        String className = error.getClass().getSimpleName();
        String message = error.getMessage();
        return new ExceptionInfo(className, message, null);
    }

    @SerializedName("class")
    private final String className;
    private final String message;
    private final String description;

    /**
     * Constructor
     * @param className the name of the exception class
     * @throws ArgumentNullException if the name is null or whitespace
     */
    public ExceptionInfo(String className) throws ArgumentNullException {
        this(className, null, null);
    }

    /**
     * Constructor
     * @param className the name of the exception class
     * @param message the exception message
     * @param description a human readable description of the exception
     * @throws ArgumentNullException if className is null or whitespace
     */
    public ExceptionInfo(String className, String message, String description) throws ArgumentNullException {
        Validate.isNotNullOrWhitespace(className, "className");
        this.className = className;
        this.message = message;
        this.description = description;
    }

    /**
     * @return the name of the exception class
     */
    public String className() {
        return this.className;
    }

    /**
     * Set the className on a copy of this ExceptionInfo
     * @param className the new className
     * @return a copy of this ExceptionInfo with className overridden
     * @throws ArgumentNullException if className is null or whitespace
     */
    public ExceptionInfo className(String className) throws ArgumentNullException {
        return new ExceptionInfo(className, message, description);
    }

    /**
     * @return the exception message
     */
    public String message() {
        return this.message;
    }

    /**
     * Set the message on a copy of this ExceptionInfo
     * @param message the new message
     * @return a copy of this ExceptionInfo with message overridden
     */
    public ExceptionInfo message(String message) {
        return new ExceptionInfo(className, message, description);
    }

    /**
     * @return a human readable description of the exception
     */
    public String description() {
        return this.description;
    }

    /**
     * Set the description on a copy of this ExceptionInfo
     * @param description the new description
     * @return a copy of this ExceptionInfo with description overriden
     */
    public ExceptionInfo description(String description) {
        return new ExceptionInfo(className, message, description);
    }
}

Document ExceptionInfo and remove uneeded try/catches