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

org.vfdtech.exceptions.CustomException Maven / Gradle / Ivy

Go to download

A utilities service with generic tools implementation. Can be plugged into your java project. This is designed for Java 1.8

There is a newer version: 1.0.0
Show newest version
package org.vfdtech.exceptions;

import lombok.Getter;
import lombok.Setter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.vfdtech.MessageContent;

import java.util.NoSuchElementException;

@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CustomException extends Exception {
    private static final long serialVersionUID = -1335544445896736296L;

    private String message;
    Object data;
    boolean success;

    public CustomException(String message, Object data) {
        this.success = false;
        this.message = message;
        this.data = data;
    }

    public CustomException(CustomException e) {
        this.success = e.isSuccess();
        this.message = e.getMessage();
        this.data = e.getData();
    }

    public CustomException(Exception e) throws CustomException {
        if (e.getClass().isAssignableFrom(CustomException.class)) {
            throw new CustomException(e.getMessage());
        } else if (e.getClass().isAssignableFrom(NoSuchElementException.class)) {
            throw new CustomException(MessageContent.noRecordFound);
        } else {
            throw new CustomException(MessageContent.errorOccurred);
        }
    }

    public CustomException(String message) {
        this.message = message;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy