All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eg.agent.android.harvest.crash.ExceptionInfo Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package com.eg.agent.android.harvest.crash;


import com.eg.agent.android.harvest.type.HarvestableObject;
import com.eg.google.gson.JsonObject;
import com.eg.google.gson.JsonPrimitive;

public class ExceptionInfo extends HarvestableObject {
    private String className;
    private String message;

    public ExceptionInfo() {
    }

    public ExceptionInfo(Throwable throwable) {
        if (throwable.getClass().getName().equalsIgnoreCase("com.newrelic.agent.android.unity.UnityException")) {
            this.className = throwable.toString();
        } else {
            this.className = throwable.getClass().getName();
        }
        if (throwable.getMessage() != null) {
            this.message = throwable.getMessage();
        } else {
            this.message = "";
        }
    }

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

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

    public JsonObject asJsonObject() {
        JsonObject data = new JsonObject();
        data.add("name", new JsonPrimitive(this.className != null ? this.className : ""));
        data.add("cause", new JsonPrimitive(this.message != null ? this.message : ""));
        return data;
    }

    public static ExceptionInfo newFromJson(JsonObject jsonObject) {
        ExceptionInfo info = new ExceptionInfo();
        info.className = jsonObject.has("name") ? jsonObject.get("name").getAsString() : "";
        info.message = jsonObject.has("cause") ? jsonObject.get("cause").getAsString() : "";
        return info;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy